fix: stabilize flaky server API and spread gate tests
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Serialize agent WebSocket writes (ping + JSON), mutex-protect spreadGateClock, and harden deploy-plan spread route hint setup under parallel test runs.
This commit is contained in:
@@ -92,6 +92,25 @@ func testAgentClientIP(agentID string) string {
|
||||
return fmt.Sprintf("10.42.%d.%d", (sum%250)+1, ((sum/250)%250)+1)
|
||||
}
|
||||
|
||||
func waitForHubAgents(t *testing.T, hub *WSHub, agentIDs ...string) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(3 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
allConnected := true
|
||||
for _, id := range agentIDs {
|
||||
if !hub.isAgentConnected(id) {
|
||||
allConnected = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if allConnected {
|
||||
return
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
t.Fatalf("agents not connected: %v", agentIDs)
|
||||
}
|
||||
|
||||
func connectTestAgent(t *testing.T, hub *WSHub, agentID string) *websocket.Conn {
|
||||
t.Helper()
|
||||
srv := httptest.NewServer(http.HandlerFunc(hub.HandleAgentWS))
|
||||
|
||||
Reference in New Issue
Block a user