← Back to team overview

testtools-dev team mailing list archive

[Bug 666345] Re: test_spinner.TestRunInReactor.test_clean_running_threads fails with an extra thread

 

This is a twisted bug in the suggestPoolSize code path - it does not
synchronise thread removal from the thread pool.

in threadpool.py:
_worker will remove the thread from self.threads when it receives WorkerStop
stop will join() threads that *are* in self.threads when stop was called
threads that *are stopped due to pool size changes are never join()ed*.

So the race is this:
 - _spinner calls suggestPoolSize(0) which asks threads to stop. These threads are not joined. ever.
 - threads go to thread heaven by removing themselves from .threads
 - _spinner triggers a stop()
 - which sees an empty threads dict *IFF* the test worker had already seen WorkerStop
 - if stop saw an empty threads dict, it doesn't call join() and the thread object is still around.

We need to work around this, and upstream twisted needs to actually join
all threads, not just those that happened to be running at stop() being
called.

To work around it, stop calling self._reactor.suggestThreadPoolSize(0)

-- 
You received this bug notification because you are a member of testtools
developers, which is subscribed to testtools.
https://bugs.launchpad.net/bugs/666345

Title:
  test_spinner.TestRunInReactor.test_clean_running_threads fails with an extra thread

Status in testtools:
  Triaged

Bug description:
  ======================================================================
FAIL: testtools.tests.test_spinner.TestRunInReactor.test_clean_running_threads
----------------------------------------------------------------------
Text attachment: traceback
------------
Traceback (most recent call last):
  File "C:\bzr\testtools\testtools\runtest.py", line 143, in _run_user
    return fn(*args)
  File "C:\bzr\testtools\testtools\testcase.py", line 539, in _run_test_method
    return self._get_test_method()()
  File "C:\bzr\testtools\testtools\tests\test_spinner.py", line 241, in test_clean_running_threads
    self.assertThat(list(threading.enumerate()), Equals(current_threads))
  File "C:\bzr\testtools\testtools\testcase.py", line 384, in assertThat
    self.fail('Match failed. Matchee: "%s"\nMatcher: %s\nDifference: %s\n'
AssertionError: Match failed. Matchee: "[<_MainThread(MainThread, started)>, <Thread(PoolThread-twisted.internet.reactor-1, stopped)>]"
Matcher: Equals([<_MainThread(MainThread, started)>])
Difference: !=:
reference = [<_MainThread(MainThread, started)>]
actual = [<_MainThread(MainThread, started)>,
 <Thread(PoolThread-twisted.internet.reactor-1, stopped)>]

This may be related to my OS, my Python version (2.4) or my twisted version (8.1.0).





References