Skip to content

Commit

Permalink
Merge pull request #16 from twisted/threadpool-argh
Browse files Browse the repository at this point in the history
Fix failing threading test
  • Loading branch information
glyph committed Oct 6, 2015
2 parents 0ef56aa + 22283b6 commit 966b5f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
sudo: false

language: "python"

branches:
Expand All @@ -12,7 +14,7 @@ matrix:
install:
# Tools for checking coverage and uploading to coveralls
- pip install coveralls coverage
- pip install .
- pip install "cryptography<1.0.0" .

script:
- coverage run --branch --source=epsilon $(type -p trial) epsilon
Expand Down
18 changes: 11 additions & 7 deletions epsilon/test/test_structlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import threading

from twisted.trial import unittest
from twisted.internet.threads import deferToThread
from twisted.internet.defer import gatherResults
from epsilon.structlike import record
from twisted.internet import reactor
from twisted.internet.defer import gatherResults
from twisted.internet.threads import deferToThreadPool
from twisted.python.threadpool import ThreadPool
from twisted.trial import unittest


class MyRecord(record('something somethingElse')):
Expand Down Expand Up @@ -144,6 +146,10 @@ def test_threadLocality(self):
look the same (i.e. the repr state tracking for '...' should be
thread-local).
"""
pool = ThreadPool(2, 2)
pool.start()
self.addCleanup(pool.stop)

class StickyRepr(object):
"""
This has a __repr__ which will block until a separate thread
Expand All @@ -161,7 +167,7 @@ def __repr__(self):
return 'sticky'
r = StickyRepr()
mr = MyRecord(something=1, somethingElse=r)
d = deferToThread(repr, mr)
d = deferToThreadPool(reactor, pool, repr, mr)
def otherRepr():
# First we wait for the first thread doing a repr() to enter its
# __repr__()...
Expand All @@ -174,13 +180,11 @@ def otherRepr():
# Now we're done, wake up the other repr and let it complete.
r.wait.set()
return result
d2 = deferToThread(otherRepr)
d2 = deferToThreadPool(reactor, pool, otherRepr)

def done((thread1repr, thread2repr)):
knownGood = 'MyRecord(something=1, somethingElse=sticky)'
# self.assertEquals(thread1repr, thread2repr)
self.assertEquals(thread1repr, knownGood)
self.assertEquals(thread2repr, knownGood)
return gatherResults([d, d2]).addCallback(done)


0 comments on commit 966b5f3

Please sign in to comment.