Skip to content

Commit f0af9df

Browse files
author
Fabien Coelho
committed
blind test with actual threads
1 parent c5063d8 commit f0af9df

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test.py

+20
Original file line numberDiff line numberDiff line change
@@ -656,4 +656,24 @@ def banged(s: str, n: int) -> str:
656656
assert banged("a", 3) == "aaa!" # hit
657657
assert cache.hits() == 0.5
658658

659+
# reset stats
660+
cache.reset()
661+
662+
import threading
663+
NTHREADS = 4
664+
barrier = threading.barrier(NTHREADS, timeout=2)
665+
666+
def run():
667+
barrier.wait()
668+
for s in ("a", "b", "c"):
669+
for n in range(3):
670+
assert banged(s, n) == s * n + "!"
671+
barrier.wait()
672+
673+
threads = [ threading.Thread(target=run, name=f"thread {i}") for i in range(NTHREADS) ]
674+
map(lambda t: t.start(), threads)
675+
map(lambda t: t.join(), threads)
676+
677+
assert cache.hits() == 0.25
678+
659679
assert not sys._is_gil_enabled()

0 commit comments

Comments
 (0)