tests: avoid losing trace2 socket readiness signal

The trace2 socket test uses a Condition to wait for its server to start
listening. If the server calls notify() before the test starts waiting,
the notification is lost and the test waits for the full 120-second
timeout before continuing.

Use an Event for the readiness signal instead.
Once the server starts listening, the event stays set, so the test can
continue immediately even if the server becomes ready before the test
starts waiting.

Change-Id: I0e8e192d997c8bd785bcefa5d5b91493f93863e8
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/630861
Tested-by: Victor Pushkarev <corvinus.v@gmail.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Victor Pushkarev <corvinus.v@gmail.com>
This commit is contained in:
Victor Pushkarev
2026-09-16 04:53:31 -07:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 4b3ada1781
commit fb4a91060e
+5 -9
View File
@@ -33,7 +33,7 @@ import platform_utils
def server_logging_thread(
socket_path: str,
server_ready: threading.Condition,
server_ready: threading.Event,
received_traces: List[str],
) -> None:
"""Helper function to receive logs over a Unix domain socket.
@@ -43,8 +43,7 @@ def server_logging_thread(
Args:
socket_path: path to a Unix domain socket on which to listen for traces
server_ready: a threading.Condition used to signal to the caller that
this thread is ready to accept connections
server_ready: event set when the server is ready to accept connections
received_traces: a list to which received traces will be appended (after
decoding to a utf-8 string).
"""
@@ -53,8 +52,7 @@ def server_logging_thread(
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.bind(socket_path)
sock.listen(0)
with server_ready:
server_ready.notify()
server_ready.set()
with sock.accept()[0] as conn:
while True:
recved = conn.recv(4096)
@@ -404,7 +402,7 @@ def test_write_socket(event_log: git_trace2_event_log.EventLog) -> None:
received_traces: List[str] = []
with tempfile.TemporaryDirectory(prefix="test_server_sockets") as tempdir:
socket_path = os.path.join(tempdir, "server.sock")
server_ready = threading.Condition()
server_ready = threading.Event()
# Start "server" listening on Unix domain socket at socket_path.
server_thread = threading.Thread(
target=server_logging_thread,
@@ -412,9 +410,7 @@ def test_write_socket(event_log: git_trace2_event_log.EventLog) -> None:
)
try:
server_thread.start()
with server_ready:
server_ready.wait(timeout=120)
server_ready.wait(timeout=120)
event_log.StartEvent([])
path = event_log.Write(path=f"af_unix:{socket_path}")