Skip to content

Agent Mesh

test: poll for control-plane and router readiness instead of sleeping

Antonio Ojeaa6ca082380e3
diff --git a/tests/integration/minimal_helpers_test.go b/tests/integration/minimal_helpers_test.go
index e7646350..c0da5af2 100644
--- a/tests/integration/minimal_helpers_test.go
+++ b/tests/integration/minimal_helpers_test.go
@@ -615,18 +615,28 @@ func waitForControlPlane(t *testing.T, port int) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
+ var lastErr error
+ var lastStatus int
for {
resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d/info", port))
if err == nil {
+ lastStatus = resp.StatusCode
_ = resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return
}
+ lastErr = nil
+ } else {
+ lastErr = err
+ lastStatus = 0
}
select {
case <-ctx.Done():
- t.Fatalf("timed out waiting for control plane: %v", err)
+ if lastErr != nil {
+ t.Fatalf("timed out waiting for control plane /info: last error: %v", lastErr)
+ }
+ t.Fatalf("timed out waiting for control plane /info: last HTTP status %d", lastStatus)
case <-time.After(100 * time.Millisecond):
}
}
diff --git a/tests/integration/multimaster_test.go b/tests/integration/multimaster_test.go
index 847c0935..82ea42bf 100644
--- a/tests/integration/multimaster_test.go
+++ b/tests/integration/multimaster_test.go
@@ -147,7 +147,7 @@ roles: []
defer func() { _ = cmdRouterA.Process.Kill(); _ = cmdRouterA.Wait() }()
// Wait for Router A to renew lease and register in CP A
- time.Sleep(3 * time.Second)
+ waitForActiveRouters(t, portA, 1, 5*time.Second)
// 5. Start Control Plane B (sharing CP A's keys)
cmdCP_B := exec.Command(cpBin,
@@ -185,7 +185,10 @@ roles: []
defer func() { _ = cmdRouterB.Process.Kill(); _ = cmdRouterB.Wait() }()
// Wait for Router B to renew lease and register in CP B
- time.Sleep(3 * time.Second)
+ peerInfoListB := waitForActiveRouters(t, portB, 1, 5*time.Second)
+ if len(peerInfoListB) != 1 {
+ t.Fatalf("expected 1 router registered on CP B, got %d", len(peerInfoListB))
+ }
// 6. Fetch router peer IDs
peerInfoListA := fetchActiveRouters(t, portA)
@@ -193,11 +196,6 @@ roles: []
t.Fatalf("expected 1 router registered on CP A, got %d", len(peerInfoListA))
}
peerIDA := peerInfoListA[0]
-
- peerInfoListB := fetchActiveRouters(t, portB)
- if len(peerInfoListB) != 1 {
- t.Fatalf("expected 1 router registered on CP B, got %d", len(peerInfoListB))
- }
peerIDB := peerInfoListB[0]
// ASSERT: Router A and Router B have unique Peer IDs