From 80fbce863d607136515f45c29f57a933309f3fa5 Mon Sep 17 00:00:00 2001 From: Harenome Ranaivoarivony-Razanajato Date: Fri, 13 Nov 2026 17:52:36 +0100 Subject: [PATCH] Check the judge batch overlap with a barrier, not wall time The test asserted that 16 calls of 0.1 s end in less than 0.8 s. On a loaded machine the wall time grows, and the test failed although the calls ran at the same time. Each call now waits on a barrier of CONCURRENCY parties. The barrier lets the calls go only when that many are in flight at once. Serial calls break it at its timeout and the test fails. The batch has 2 * CONCURRENCY items, so the barrier fills twice for any value of CONCURRENCY. The count and order checks are the same. --- app/ui_tests/test_judge_batch.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/ui_tests/test_judge_batch.py b/app/ui_tests/test_judge_batch.py index 5d2b74c6..c8410f58 100644 --- a/app/ui_tests/test_judge_batch.py +++ b/app/ui_tests/test_judge_batch.py @@ -7,7 +7,6 @@ from __future__ import annotations import threading -import time import unittest from nullius.judge import client @@ -18,22 +17,17 @@ class RunBatch(unittest.TestCase): def test_calls_overlap_and_the_count_and_order_hold(self): - live, most = [0], [0] - lock = threading.Lock() + # Each call waits until CONCURRENCY calls are in flight at once, twice over n items. + # Serial calls break the barrier at its timeout, which only bounds a hang. + n = 2 * judge.CONCURRENCY + in_flight = threading.Barrier(judge.CONCURRENCY, timeout=10) def ask(i): - with lock: - live[0] += 1; most[0] = max(most[0], live[0]) - time.sleep(0.1) - with lock: - live[0] -= 1 + in_flight.wait() if i == 3: raise client.JudgeError(500, "busy") - t0 = time.monotonic() - done, failed = judge.run_batch(list(range(16)), ask, lambda i: f"t{i}") - self.assertEqual((done, failed), (15, ["t3: busy"])) - self.assertGreater(most[0], 1) - self.assertLess(time.monotonic() - t0, 16 * 0.1 / 2) + done, failed = judge.run_batch(list(range(n)), ask, lambda i: f"t{i}") + self.assertEqual((done, failed), (n - 1, ["t3: busy"])) def test_a_refused_key_starts_no_further_call(self): asked = []