mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-23 20:25:56 +00:00
Wait for slot release in the WebSocket connection limit test
Agent removal occurs inside read-loop cleanup before the handler releases its per-IP connection slot. The flood test could observe the first state and retry while the slot was still occupied, causing a spurious rejection. Wait for the guarded admission count to reach zero before reconnecting, while preserving rejection at capacity and successful registration after release.
This commit is contained in:
@@ -672,6 +672,7 @@ func TestHandleWebSocket_RejectsPerIPConnectionFlood(t *testing.T) {
|
||||
t.Fatalf("Dial first connection: %v", err)
|
||||
}
|
||||
defer firstConn.Close()
|
||||
remoteIP := normalizeWebSocketRemoteIP(firstConn.LocalAddr().String())
|
||||
|
||||
wsWriteMessage(t, firstConn, mustNewMessage(t, MsgTypeAgentRegister, "", AgentRegisterPayload{
|
||||
AgentID: "a1",
|
||||
@@ -699,6 +700,13 @@ func TestHandleWebSocket_RejectsPerIPConnectionFlood(t *testing.T) {
|
||||
|
||||
firstConn.Close()
|
||||
waitFor(t, 2*time.Second, func() bool { return !s.IsAgentConnected("a1") })
|
||||
// The read loop removes the agent before the handler's deferred slot release.
|
||||
// Wait for admission capacity itself before testing that it can be reused.
|
||||
waitFor(t, 2*time.Second, func() bool {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.ipConnCounts[remoteIP] == 0
|
||||
})
|
||||
|
||||
thirdConn, _, err := dialAgentExecWebSocket(t, ts.URL)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user