update some tests

This commit is contained in:
Maycon Santos
2025-07-18 19:30:24 +02:00
parent e66412da1b
commit 7b4cc63054
5 changed files with 13 additions and 14 deletions
+2 -5
View File
@@ -7,7 +7,6 @@ import (
"time"
"github.com/google/uuid"
"golang.org/x/exp/maps"
nblog "github.com/netbirdio/netbird/client/firewall/uspfilter/log"
nftypes "github.com/netbirdio/netbird/client/internal/netflow/types"
@@ -220,10 +219,8 @@ func (t *UDPTracker) sendEvent(typ nftypes.Type, conn *UDPConnTrack, ruleID []by
})
}
func (t *UDPTracker) getConnections() map[ConnKey]*UDPConnTrack {
func (t *UDPTracker) getConnectionsLen() int {
t.mutex.RLock()
defer t.mutex.RUnlock()
copyConn := make(map[ConnKey]*UDPConnTrack, len(t.connections))
maps.Copy(copyConn, t.connections)
return copyConn
return len(t.connections)
}
@@ -202,13 +202,13 @@ func TestUDPTracker_Cleanup(t *testing.T) {
}
// Verify initial connections
assert.Len(t, tracker.getConnections(), 2)
assert.Equal(t, 2, tracker.getConnectionsLen())
// Wait for connection timeout and cleanup interval
time.Sleep(timeout + 2*cleanupInterval)
tracker.mutex.RLock()
connCount := len(tracker.getConnections())
connCount := tracker.getConnectionsLen()
tracker.mutex.RUnlock()
// Verify connections were cleaned up