test(report-relay): prime the label cache so the asserted path never refetches
The first relay test was flaky in CI (labels [] != [3,9]). Root cause: Gitea.label_ids() fetches lazily on the first report and silently falls back to [] on any fetch error; under CI load that first live fetch -- happening inside the asserted POST -- intermittently raced the mock server thread and dropped the labels. The earlier readiness probe only proved reachability at setUp, not during the POST. Fix: fetch labels once in setUp, while the mock is known-reachable, with a bounded retry. label_ids caches for 10 minutes, so every request handler now resolves labels from cache and the live fetch is off the asserted path. Verified 25/25 clean and 12/12 under 2x CPU oversubscription. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
This commit is contained in:
@@ -88,8 +88,21 @@ class RelayTests(unittest.TestCase):
|
||||
self.now = [1000.0]
|
||||
self.limiter = relay.RateLimiter(2, 3, clock=lambda: self.now[0])
|
||||
self.logs = []
|
||||
r = relay.Relay(relay.Gitea(self.gitea.url, "blueflare/alkane-toolkit", TOKEN),
|
||||
self.limiter, log=self.logs.append)
|
||||
client = relay.Gitea(self.gitea.url, "blueflare/alkane-toolkit", TOKEN)
|
||||
# Prime the relay's label cache now, while the mock is known-reachable
|
||||
# (its __init__ readiness probe just succeeded). Gitea.label_ids() caches
|
||||
# for 10 minutes and silently falls back to [] on any fetch error, so if
|
||||
# the handlers below did the first fetch themselves it would race the
|
||||
# mock's server thread under CI load and intermittently drop the labels
|
||||
# to [] -- the actual cause of the first test's flakiness. Fetching here,
|
||||
# with a bounded retry, makes every handler resolve labels from cache and
|
||||
# removes the live fetch from the asserted path entirely.
|
||||
deadline = time.monotonic() + 5
|
||||
while not client.label_ids(["feature"]):
|
||||
if time.monotonic() >= deadline:
|
||||
raise RuntimeError("mock Gitea never served labels to the relay client")
|
||||
time.sleep(0.02)
|
||||
r = relay.Relay(client, self.limiter, log=self.logs.append)
|
||||
self.server = ThreadingHTTPServer(("127.0.0.1", 0), relay.make_handler(r))
|
||||
threading.Thread(target=self.server.serve_forever, daemon=True).start()
|
||||
self.url = f"http://127.0.0.1:{self.server.server_address[1]}"
|
||||
|
||||
Reference in New Issue
Block a user