mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-22 14:49:10 +02:00
add race flag to client tests
using for now a temp fixed for ice
This commit is contained in:
@@ -7,6 +7,7 @@ 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"
|
||||
@@ -218,3 +219,11 @@ func (t *UDPTracker) sendEvent(typ nftypes.Type, conn *UDPConnTrack, ruleID []by
|
||||
TxBytes: conn.BytesTx.Load(),
|
||||
})
|
||||
}
|
||||
|
||||
func (t *UDPTracker) getConnections() map[ConnKey]*UDPConnTrack {
|
||||
t.mutex.RLock()
|
||||
defer t.mutex.RUnlock()
|
||||
copyConn := make(map[ConnKey]*UDPConnTrack, len(t.connections))
|
||||
maps.Copy(copyConn, t.connections)
|
||||
return copyConn
|
||||
}
|
||||
|
||||
@@ -202,13 +202,13 @@ func TestUDPTracker_Cleanup(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify initial connections
|
||||
assert.Len(t, tracker.connections, 2)
|
||||
assert.Len(t, tracker.getConnections(), 2)
|
||||
|
||||
// Wait for connection timeout and cleanup interval
|
||||
time.Sleep(timeout + 2*cleanupInterval)
|
||||
|
||||
tracker.mutex.RLock()
|
||||
connCount := len(tracker.connections)
|
||||
connCount := len(tracker.getConnections())
|
||||
tracker.mutex.RUnlock()
|
||||
|
||||
// Verify connections were cleaned up
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -135,20 +136,26 @@ func TestUpstreamResolver_DeactivationReactivation(t *testing.T) {
|
||||
responseWriter := &test.MockResponseWriter{
|
||||
WriteMsgFunc: func(m *dns.Msg) error { return nil },
|
||||
}
|
||||
|
||||
lmux := sync.Mutex{}
|
||||
failed := false
|
||||
resolver.deactivate = func(error) {
|
||||
lmux.Lock()
|
||||
failed = true
|
||||
lmux.Unlock()
|
||||
}
|
||||
|
||||
reactivated := false
|
||||
resolver.reactivate = func() {
|
||||
lmux.Lock()
|
||||
reactivated = true
|
||||
lmux.Unlock()
|
||||
}
|
||||
|
||||
resolver.ServeDNS(responseWriter, new(dns.Msg).SetQuestion("one.one.one.one.", dns.TypeA))
|
||||
|
||||
if !failed {
|
||||
lmux.Lock()
|
||||
failedCheck := failed
|
||||
lmux.Unlock()
|
||||
if !failedCheck {
|
||||
t.Errorf("expected that resolving was deactivated")
|
||||
return
|
||||
}
|
||||
@@ -160,7 +167,10 @@ func TestUpstreamResolver_DeactivationReactivation(t *testing.T) {
|
||||
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
|
||||
if !reactivated {
|
||||
lmux.Lock()
|
||||
checkReactivated := reactivated
|
||||
lmux.Unlock()
|
||||
if !checkReactivated {
|
||||
t.Errorf("expected that resolving was reactivated")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -836,7 +836,10 @@ func (e *Engine) updateSSH(sshConf *mgmProto.SSHConfig) error {
|
||||
}
|
||||
go func() {
|
||||
// blocking
|
||||
err = e.sshServer.Start()
|
||||
e.syncMsgMux.Lock()
|
||||
sshServer := e.sshServer
|
||||
e.syncMsgMux.Unlock()
|
||||
err = sshServer.Start()
|
||||
if err != nil {
|
||||
// will throw error when we stop it even if it is a graceful stop
|
||||
log.Debugf("stopped SSH server with error %v", err)
|
||||
@@ -851,6 +854,8 @@ func (e *Engine) updateSSH(sshConf *mgmProto.SSHConfig) error {
|
||||
}
|
||||
} else if !isNil(e.sshServer) {
|
||||
// Disable SSH server request, so stop it if it was running
|
||||
e.syncMsgMux.Lock()
|
||||
defer e.syncMsgMux.Unlock()
|
||||
err := e.sshServer.Stop()
|
||||
if err != nil {
|
||||
log.Warnf("failed to stop SSH server %v", err)
|
||||
|
||||
@@ -102,3 +102,11 @@ func (m *Manager) notify(peerConnID peerid.ConnID) {
|
||||
case m.OnActivityChan <- peerConnID:
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) getPeerListener(peerConnID peerid.ConnID) (*Listener, bool) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
listener, ok := m.peers[peerConnID]
|
||||
return listener, ok
|
||||
}
|
||||
|
||||
@@ -50,8 +50,11 @@ func TestManager_MonitorPeerActivity(t *testing.T) {
|
||||
if err := mgr.MonitorPeerActivity(peerCfg1); err != nil {
|
||||
t.Fatalf("failed to monitor peer activity: %v", err)
|
||||
}
|
||||
|
||||
if err := trigger(mgr.peers[peerCfg1.PeerConnID].conn.LocalAddr().String()); err != nil {
|
||||
listener, ok := mgr.getPeerListener(peerCfg1.PeerConnID)
|
||||
if !ok {
|
||||
t.Fatalf("failed to get peer listener: %s", peerCfg1.PeerConnID)
|
||||
}
|
||||
if err := trigger(listener.conn.LocalAddr().String()); err != nil {
|
||||
t.Fatalf("failed to trigger activity: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,30 +9,54 @@ type mocListener struct {
|
||||
lastState int
|
||||
wg sync.WaitGroup
|
||||
peers int
|
||||
mux sync.Mutex
|
||||
}
|
||||
|
||||
func (l *mocListener) OnConnected() {
|
||||
l.mux.Lock()
|
||||
defer l.mux.Unlock()
|
||||
l.lastState = stateConnected
|
||||
l.wg.Done()
|
||||
}
|
||||
func (l *mocListener) OnDisconnected() {
|
||||
l.mux.Lock()
|
||||
defer l.mux.Unlock()
|
||||
l.lastState = stateDisconnected
|
||||
l.wg.Done()
|
||||
}
|
||||
func (l *mocListener) OnConnecting() {
|
||||
l.mux.Lock()
|
||||
defer l.mux.Unlock()
|
||||
l.lastState = stateConnecting
|
||||
l.wg.Done()
|
||||
}
|
||||
func (l *mocListener) OnDisconnecting() {
|
||||
l.mux.Lock()
|
||||
defer l.mux.Unlock()
|
||||
l.lastState = stateDisconnecting
|
||||
l.wg.Done()
|
||||
|
||||
}
|
||||
|
||||
func (l *mocListener) getLastState() int {
|
||||
l.mux.Lock()
|
||||
defer l.mux.Unlock()
|
||||
return l.lastState
|
||||
}
|
||||
|
||||
func (l *mocListener) OnAddressChanged(host, addr string) {
|
||||
|
||||
}
|
||||
func (l *mocListener) OnPeersListChanged(size int) {
|
||||
l.mux.Lock()
|
||||
l.peers = size
|
||||
l.mux.Unlock()
|
||||
}
|
||||
|
||||
func (l *mocListener) getPeers() int {
|
||||
l.mux.Lock()
|
||||
defer l.mux.Unlock()
|
||||
return l.peers
|
||||
}
|
||||
|
||||
func (l *mocListener) setWaiter() {
|
||||
@@ -77,7 +101,7 @@ func Test_notifier_SetListener(t *testing.T) {
|
||||
n.lastNotification = stateConnecting
|
||||
n.setListener(listener)
|
||||
listener.wait()
|
||||
if listener.lastState != n.lastNotification {
|
||||
if listener.getLastState() != n.lastNotification {
|
||||
t.Errorf("invalid state: %d, expected: %d", listener.lastState, n.lastNotification)
|
||||
}
|
||||
}
|
||||
@@ -91,7 +115,7 @@ func Test_notifier_RemoveListener(t *testing.T) {
|
||||
n.removeListener()
|
||||
n.peerListChanged(1)
|
||||
|
||||
if listener.peers != 0 {
|
||||
if listener.getPeers() != 0 {
|
||||
t.Errorf("invalid state: %d", listener.peers)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user