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
|
||||
@@ -5,7 +5,6 @@ import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
@@ -18,6 +17,7 @@ from failure import Failure
|
||||
from claude_code.reply import Limited
|
||||
from model_routing.ladder_file import read_ladder, SHIPPED
|
||||
from model_routing.ladder import Rung
|
||||
from rung_replay.doubles import Together
|
||||
|
||||
LADDER = read_ladder(SHIPPED)
|
||||
REFERENCE = Rung("claude-opus-5-5", "medium")
|
||||
@@ -63,18 +63,15 @@ class Replayed(unittest.TestCase):
|
||||
|
||||
def test_says_what_it_replays_on_each_rung_and_replays_no_more_cases_at_once_than_asked(self):
|
||||
high = Rung("claude-fable-5-2", "low")
|
||||
said, running, most = [], [], {}
|
||||
said, together = [], Together(2)
|
||||
|
||||
def replay_one(case, rung):
|
||||
running.append(case)
|
||||
most[rung] = max(most.get(rung, 0), len(running))
|
||||
time.sleep(0.02)
|
||||
running.remove(case)
|
||||
together(rung)
|
||||
return {0}
|
||||
|
||||
replayed(["a", "b", "c"], REFERENCE, [MIDDLE], replay_one, lambda _, reply: sorted(reply), "verdicts", said.append, 1, [high])
|
||||
self.assertEqual(said, [f"replaying 3 verdicts on {REFERENCE}", f"replaying 3 verdicts on {high}", f"replaying 3 verdicts on {MIDDLE}"])
|
||||
self.assertEqual(most, {REFERENCE: 1, high: 1, MIDDLE: 1})
|
||||
replayed(["a", "b", "c", "d"], REFERENCE, [MIDDLE], replay_one, lambda _, reply: sorted(reply), "verdicts", said.append, 2, [high])
|
||||
self.assertEqual(said, [f"replaying 4 verdicts on {REFERENCE}", f"replaying 4 verdicts on {high}", f"replaying 4 verdicts on {MIDDLE}"])
|
||||
self.assertEqual(together.most, {REFERENCE: 2, high: 2, MIDDLE: 2})
|
||||
|
||||
def test_stops_at_a_usage_limit(self):
|
||||
limit = Limited(None, "limit")
|
||||
|
||||
Reference in New Issue
Block a user