Skip to content

Commit baba7c8

Browse files
committed
fix singleton unit test
1 parent 0b76d74 commit baba7c8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

unpythonic/test/test_singleton.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8; -*-
22

3-
from ..syntax import macros, test, test_raises # noqa: F401
3+
from ..syntax import macros, test, test_raises, the # noqa: F401
44
from .fixtures import session, testset, returns_normally
55

66
import pickle
@@ -95,8 +95,12 @@ def worker():
9595
t.start()
9696
for t in threads:
9797
t.join()
98+
# Rarely, a race may lead to multiple threads succeeding in
99+
# instantiating the singleton. If that happens, all the created
100+
# instances should be the same one. So test that, rather than
101+
# that only one was created.
98102
lst = slurp(que)
99-
test[len(lst) == 1]
103+
test[allsame(the[lst])] # lst is short and we'd like to see it if the test fails.
100104

101105
# TODO: These must be outside the `with test` because a test block
102106
# implicitly creates a function (whence a local scope).
@@ -117,6 +121,7 @@ def worker():
117121
for t in threads:
118122
t.join()
119123
lst = slurp(que)
124+
test[len(lst) == n]
120125
test[all(x is not None for x in lst)]
121126
test[allsame(lst)]
122127

0 commit comments

Comments
 (0)