Answer stability round 1: 0 🔴, 4 🟡 (0 misread); a cycle's close takes the task from the cycle, a resolved thread is skipped unread, and tests run git in their own environment
CI / tests (pull_request) Successful in 3m56s
CI / tests (pull_request) Successful in 3m56s
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""Test doubles for what a replay runs at once."""
|
||||
import collections
|
||||
import threading
|
||||
import typing
|
||||
|
||||
|
||||
class Together:
|
||||
"""What a fake replay calls to show how many replays run at once: each call returns once `parties` calls are inside it together, so it neither sleeps nor reads a clock."""
|
||||
|
||||
def __init__(self, parties: int) -> None:
|
||||
# The timeout only ends a test whose replays never run `parties` at once: it breaks the barrier, which raises in every call.
|
||||
self.barrier = threading.Barrier(parties, timeout=60)
|
||||
self.lock = threading.Lock()
|
||||
self.inside = 0
|
||||
# The most calls inside at once, by the key each call gave.
|
||||
self.most: dict[typing.Hashable, int] = collections.defaultdict(int)
|
||||
|
||||
def __call__(self, key: typing.Hashable) -> None:
|
||||
with self.lock:
|
||||
self.inside += 1
|
||||
self.most[key] = max(self.most[key], self.inside)
|
||||
try:
|
||||
self.barrier.wait()
|
||||
finally:
|
||||
with self.lock:
|
||||
self.inside -= 1
|
||||
Reference in New Issue
Block a user