From 8d9ccee4e912e8ae592e3e01b1015c96e48e97c8 Mon Sep 17 00:00:00 2001 From: Joseph Mearman Date: Wed, 21 Oct 2026 07:52:06 +0100 Subject: [PATCH] test(cluster): stop two recreate tests assuming which server takes the first turn The servers' turns come in the order their hosts' results arrive, which the role documents as not fixed. One test compared the registered nodes as an ordered list, and another expected the bootstrap server to find no peers although a server that went first had registered itself. They now compare the registered nodes as a mapping and put only the bootstrap server in the play. --- tests/unit/test_server_recreate.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_server_recreate.py b/tests/unit/test_server_recreate.py index 56179e65..b1b21348 100644 --- a/tests/unit/test_server_recreate.py +++ b/tests/unit/test_server_recreate.py @@ -313,6 +313,11 @@ def running_cluster(self, hashes: dict[str, str]) -> None: self.rendered(name, HASH_NEW) self.nodes(**{name: "True" for name in hashes}) + def registered_nodes(self) -> dict[str, str]: + """The nodes the stub holds as registered, each with its Ready condition, whatever order they registered in.""" + words = (self.stub / "cluster.nodes").read_text().split() + return dict(zip(words[::2], words[1::2], strict=True)) + def turns_do_not_overlap(self) -> None: """Every server's calls in the log lie wholly before or wholly after every other's, whichever went first.""" spans = sorted((min(self.events(f"node{n}")), max(self.events(f"node{n}"))) for n in (1, 2, 3)) @@ -330,7 +335,7 @@ def test_every_server_whose_configuration_changed_is_recreated(self) -> None: ups = [call for call in self.calls() if call.startswith("module up")] # Which server goes first is the order the hosts' results arrive in, so only the set is fixed. self.assertCountEqual(ups, [f"module up node{n} profiles=server check=False" for n in (1, 2, 3)]) - self.assertEqual((self.stub / "cluster.nodes").read_text().split(), ["node1", "True", "node2", "True", "node3", "True"]) + self.assertEqual(self.registered_nodes(), {"node1": "True", "node2": "True", "node3": "True"}) def test_a_server_is_ready_again_before_the_next_servers_turn_begins(self) -> None: # Each recreate takes its node out of Ready until the role has waited for it, so a turn that began before the wait would find that node not Ready and refuse: the run passing shows the turns do not overlap, and the log shows the order. @@ -358,7 +363,8 @@ def test_a_bootstrap_server_restarted_before_anything_joined_it_is_recreated_wit self.rendered("node2", HASH_NEW) self.rendered("node3", HASH_NEW) self.nodes(node1="True") - result = self.start() + # Only the bootstrap server takes a turn: the others' turns come in no fixed order, and one that came first would register itself before node1's turn and leave node1 a peer to wait for. + result = self.start(limit="node1") self.assertEqual(result.returncode, 0, result.stdout + result.stderr) self.assertEqual([call for call in self.calls() if call.startswith("module up node1")], ["module up node1 profiles=server check=False"]) self.assertEqual([call for call in self.calls() if " kubectl get lease " in call], [])