mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-24 08:33:41 +01:00
test(broadcast): fix flaky TestBroadcastMHFAllSessions under race detector
The fixed 100ms sleep was too short for sendLoop goroutines to drain under the race detector's scheduling overhead, causing intermittent count=4/want=5 failures. Replace with a 2s polling loop that exits as soon as all sessions report delivery.
This commit is contained in:
@@ -278,13 +278,26 @@ func TestBroadcastMHFAllSessions(t *testing.T) {
|
|||||||
testPkt := &mhfpacket.MsgSysNop{}
|
testPkt := &mhfpacket.MsgSysNop{}
|
||||||
server.BroadcastMHF(testPkt, nil)
|
server.BroadcastMHF(testPkt, nil)
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
// Poll until all sessions have received the packet or the deadline is reached.
|
||||||
|
deadline := time.Now().Add(2 * time.Second)
|
||||||
|
for time.Now().Before(deadline) {
|
||||||
|
receivedCount := 0
|
||||||
|
for _, sess := range server.sessions {
|
||||||
|
mock := sess.cryptConn.(*MockCryptConn)
|
||||||
|
if mock.PacketCount() > 0 {
|
||||||
|
receivedCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if receivedCount == sessionCount {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
// Stop all sessions
|
// Stop all sessions
|
||||||
for _, sess := range sessions {
|
for _, sess := range sessions {
|
||||||
sess.closed.Store(true)
|
sess.closed.Store(true)
|
||||||
}
|
}
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
|
|
||||||
// Verify all sessions received the packet
|
// Verify all sessions received the packet
|
||||||
receivedCount := 0
|
receivedCount := 0
|
||||||
|
|||||||
Reference in New Issue
Block a user