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>
diff --git a/tests/test_git_trace2_event_log.py b/tests/test_git_trace2_event_log.py
index 13b64df..195dbaf 100644
--- a/tests/test_git_trace2_event_log.py
+++ b/tests/test_git_trace2_event_log.py
@@ -33,7 +33,7 @@
 
 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 @@
 
     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 @@
     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 @@
     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 @@
         )
         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}")