2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-12 08:12:33 +00:00

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>
This commit is contained in:
Daniel Hilst
2026-09-18 12:27:52 -03:00
parent 9b6e941166
commit b755d4ac8d
2 changed files with 31 additions and 4 deletions
@@ -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
@@ -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)