From b755d4ac8d19c54d077e1f55f18430df65bb8dc5 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 18 Sep 2026 12:27:52 -0300 Subject: [PATCH] fix(blackboxtest): collect findme callbacks for the whole window xcatd calls a discovering node back twice, processing and then processed. The callback listener returned at the first one and closed, so a late processed was missed, and the next scenario's listener on the same port received it: findme-callbacks saw 1 callback and findme-unprivileged-port saw 2. The listener now collects for the whole callback_wait window. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../src/blackboxtest_lib/xcatc.py | 12 ++++++---- xCAT-test/blackboxtest/tests/test_clients.py | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/xCAT-test/blackboxtest/src/blackboxtest_lib/xcatc.py b/xCAT-test/blackboxtest/src/blackboxtest_lib/xcatc.py index f259d672d..f80fe51e0 100644 --- a/xCAT-test/blackboxtest/src/blackboxtest_lib/xcatc.py +++ b/xCAT-test/blackboxtest/src/blackboxtest_lib/xcatc.py @@ -131,10 +131,14 @@ class Listener(object): return self.received def wait(self, seconds): - """Block until something arrives, or the time runs out.""" - deadline = time.time() + float(seconds) - while time.time() < deadline and not self.received: - time.sleep(0.05) + """Collect for the whole window. + + xcatd calls a discovering node back twice, `processing` and then + `processed`, and a scenario counts the callbacks. A listener closed at + the first one misses the second, and the next scenario's listener on + the same port receives it. + """ + time.sleep(float(seconds)) return self.received diff --git a/xCAT-test/blackboxtest/tests/test_clients.py b/xCAT-test/blackboxtest/tests/test_clients.py index e557004e1..7682979ec 100644 --- a/xCAT-test/blackboxtest/tests/test_clients.py +++ b/xCAT-test/blackboxtest/tests/test_clients.py @@ -12,6 +12,7 @@ running them needs a server, and that is the wire suite's job. import os import shutil import tempfile +import time import unittest import context # noqa: F401 @@ -301,6 +302,28 @@ class TftpCommandTests(unittest.TestCase): class XcatTransportTests(unittest.TestCase): + def test_a_listener_collects_a_late_second_callback(self): + import socket + import threading + from blackboxtest_lib import xcatc + listener = xcatc.Listener("127.0.0.1", 0).start() + port = listener._socket.getsockname()[1] + + def call(delay, text): + time.sleep(delay) + with socket.create_connection(("127.0.0.1", port)) as conn: + conn.sendall(text) + + callers = [threading.Thread(target=call, args=(0.1, b"processing")), + threading.Thread(target=call, args=(0.8, b"processed"))] + for caller in callers: + caller.start() + listener.wait(1.5) + received = listener.stop() # as request() and findme() do + for caller in callers: + caller.join() + self.assertEqual(received, ["processing", "processed"]) + def test_a_refused_port_is_an_assertable_transport_error(self): from blackboxtest_lib import xcatc reply = xcatc.request("127.0.0.1", "getdestiny", port=1, timeout=2)