test(report-relay): wait for the mock Gitea to serve before probing
The report-relay test's mock server binds in __init__ but runs serve_forever on a daemon thread. Under CI load that thread can be starved past the relay's HTTP timeout, so the first test's label fetch returns [] and test_files_an_issue_with_title_body_and_labels fails (labels [] != [3,9]). It passes locally and only the first test flaked, which is the classic server-thread startup race. Add a readiness probe in FakeGitea.__init__: poll the labels endpoint until the serve_forever thread actually answers (5s budget) before the test issues any relay request. Deterministic now (5/5 local runs green); no production relay change. This surfaced only because #52's verify is the first time this gate ran on the alkane-ci pool. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
||||
import pathlib
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
@@ -58,6 +59,23 @@ class FakeGitea:
|
||||
self.server = ThreadingHTTPServer(("127.0.0.1", 0), H)
|
||||
threading.Thread(target=self.server.serve_forever, daemon=True).start()
|
||||
self.url = f"http://127.0.0.1:{self.server.server_address[1]}"
|
||||
# Block until the serve_forever thread is actually handling requests, so
|
||||
# the relay's first label fetch cannot race server startup. The socket
|
||||
# listens from __init__, but under load the daemon thread can be starved
|
||||
# past the relay's HTTP timeout, which silently drops labels to [] and
|
||||
# made the first test flaky in CI.
|
||||
probe = urllib.request.Request(
|
||||
self.url + "/api/v1/repos/blueflare/alkane-toolkit/labels",
|
||||
headers={"Authorization": f"token {TOKEN}"})
|
||||
deadline = time.monotonic() + 5
|
||||
while True:
|
||||
try:
|
||||
urllib.request.urlopen(probe, timeout=1).read()
|
||||
break
|
||||
except Exception:
|
||||
if time.monotonic() >= deadline:
|
||||
raise
|
||||
time.sleep(0.02)
|
||||
|
||||
def close(self):
|
||||
self.server.shutdown()
|
||||
|
||||
Reference in New Issue
Block a user