Files
Paweł Gronowski 5c7bcb64ff integration/network: Fix flaky TestInspectNetwork/AfterLeaderChange
SwarmKit's Raft election timeout is 10 seconds (ElectionTick=10 ×
TickInterval=1 s). RestartNode (Stop+Start in sequence) can complete
in under 10 s on a fast machine, so followers may never detect a
leader gap: the restarted node reconnects before their election timer
fires and resumes leadership unchanged. This is the race that makes
the subtest flaky.

Fix by separating the stop and start steps:

1. Stop the leader and do NOT restart it immediately.
2. Poll a standby manager's API (standbyCli) until a different leader
   is elected. Using a non-leader manager avoids depending on the
   stopped node's API, which is unavailable during this window.
3. Start the stopped node back up. The new leader has advanced the
   Raft term, so the rejoining node is forced to become a follower.
4. Wait for c1 to be responsive again (HasLeader via c1) before
   asserting and running the inspect checks.

With the leader fully stopped (not immediately restarted), the
remaining two managers must elect a new leader - they have quorum
and the original node cannot reconnect to reset their election timer.
The election fires within the 10 s timeout, well inside NetworkPoll's
30 s ceiling (50 s on arm). The three-retry loop is removed; the
approach is deterministic.

Add HasLeaderOtherThan to integration/internal/swarm/states.go. Errors
from NodeList are treated as poll.Continue rather than poll.Error so a
brief period of cluster unavailability during the election does not
abort the wait.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2026-07-06 15:31:12 +02:00
..
2026-02-13 18:49:51 +01:00