[pypy-svn] r16322 - pypy/dist/pypy/module/thread/test
arigo at codespeak.net
arigo at codespeak.net
Tue Aug 23 19:27:12 CEST 2005
Author: arigo
Date: Tue Aug 23 19:27:11 2005
New Revision: 16322
Modified:
pypy/dist/pypy/module/thread/test/test_local.py
Log:
Fixed broken thread test: it contained a race condition if two __init__ calls
were occurring in parallel.
Modified: pypy/dist/pypy/module/thread/test/test_local.py
==============================================================================
--- pypy/dist/pypy/module/thread/test/test_local.py (original)
+++ pypy/dist/pypy/module/thread/test/test_local.py Tue Aug 23 19:27:11 2005
@@ -48,26 +48,22 @@
def test_local_init(self):
import thread
- feedback = []
- seen = {}
+ tags = [1, 2, 3, 4, 5, 54321]
+ seen = []
class X(thread._local):
def __init__(self, n):
assert n == 42
- self.tag = len(feedback)
- feedback.append(1)
+ self.tag = tags.pop()
x = X(42)
- assert x.tag == 0
- assert feedback == [1]
+ assert x.tag == 54321
def f():
- seen[x.tag] = True
+ seen.append(x.tag)
for i in range(5):
thread.start_new_thread(f, ())
self.waitfor(lambda: len(seen) == 5, timeout=20.0)
- assert seen == {1: True,
- 2: True,
- 3: True,
- 4: True,
- 5: True}
- assert len(feedback) == 6
+ seen1 = seen[:]
+ seen1.sort()
+ assert seen1 == [1, 2, 3, 4, 5]
+ assert tags == []
More information about the Pypy-commit
mailing list