mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
add race flag to client tests
using for now a temp fixed for ice
This commit is contained in:
2
.github/workflows/golang-test-darwin.yml
vendored
2
.github/workflows/golang-test-darwin.yml
vendored
@@ -42,5 +42,5 @@ jobs:
|
|||||||
run: git --no-pager diff --exit-code
|
run: git --no-pager diff --exit-code
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -tags=devcert -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE' -timeout 5m -p 1 $(go list ./... | grep -v /management)
|
run: NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -tags=devcert -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE' -race -timeout 5m -p 1 $(go list ./... | grep -v /management)
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/golang-test-linux.yml
vendored
2
.github/workflows/golang-test-linux.yml
vendored
@@ -144,7 +144,7 @@ jobs:
|
|||||||
run: git --no-pager diff --exit-code
|
run: git --no-pager diff --exit-code
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} CI=true go test -tags devcert -exec 'sudo' -timeout 10m -p 1 $(go list ./... | grep -v -e /management -e /signal -e /relay)
|
run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} CI=true go test -tags devcert -exec 'sudo' -race -timeout 10m -p 1 $(go list ./... | grep -v -e /management -e /signal -e /relay)
|
||||||
|
|
||||||
test_client_on_docker:
|
test_client_on_docker:
|
||||||
name: "Client (Docker) / Unit"
|
name: "Client (Docker) / Unit"
|
||||||
|
|||||||
2
.github/workflows/golang-test-windows.yml
vendored
2
.github/workflows/golang-test-windows.yml
vendored
@@ -66,7 +66,7 @@ jobs:
|
|||||||
- run: echo "files=$(go list ./... | ForEach-Object { $_ } | Where-Object { $_ -notmatch '/management' })" >> $env:GITHUB_ENV
|
- run: echo "files=$(go list ./... | ForEach-Object { $_ } | Where-Object { $_ -notmatch '/management' })" >> $env:GITHUB_ENV
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: PsExec64 -s -w ${{ github.workspace }} cmd.exe /c "C:\hostedtoolcache\windows\go\${{ steps.go.outputs.go-version }}\x64\bin\go.exe test -tags=devcert -timeout 10m -p 1 ${{ env.files }} > test-out.txt 2>&1"
|
run: PsExec64 -s -w ${{ github.workspace }} cmd.exe /c "C:\hostedtoolcache\windows\go\${{ steps.go.outputs.go-version }}\x64\bin\go.exe test -tags=devcert -race -timeout 10m -p 1 ${{ env.files }} > test-out.txt 2>&1"
|
||||||
- name: test output
|
- name: test output
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
run: Get-Content test-out.txt
|
run: Get-Content test-out.txt
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
|
|
||||||
nblog "github.com/netbirdio/netbird/client/firewall/uspfilter/log"
|
nblog "github.com/netbirdio/netbird/client/firewall/uspfilter/log"
|
||||||
nftypes "github.com/netbirdio/netbird/client/internal/netflow/types"
|
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(),
|
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
|
// Verify initial connections
|
||||||
assert.Len(t, tracker.connections, 2)
|
assert.Len(t, tracker.getConnections(), 2)
|
||||||
|
|
||||||
// Wait for connection timeout and cleanup interval
|
// Wait for connection timeout and cleanup interval
|
||||||
time.Sleep(timeout + 2*cleanupInterval)
|
time.Sleep(timeout + 2*cleanupInterval)
|
||||||
|
|
||||||
tracker.mutex.RLock()
|
tracker.mutex.RLock()
|
||||||
connCount := len(tracker.connections)
|
connCount := len(tracker.getConnections())
|
||||||
tracker.mutex.RUnlock()
|
tracker.mutex.RUnlock()
|
||||||
|
|
||||||
// Verify connections were cleaned up
|
// Verify connections were cleaned up
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -135,20 +136,26 @@ func TestUpstreamResolver_DeactivationReactivation(t *testing.T) {
|
|||||||
responseWriter := &test.MockResponseWriter{
|
responseWriter := &test.MockResponseWriter{
|
||||||
WriteMsgFunc: func(m *dns.Msg) error { return nil },
|
WriteMsgFunc: func(m *dns.Msg) error { return nil },
|
||||||
}
|
}
|
||||||
|
lmux := sync.Mutex{}
|
||||||
failed := false
|
failed := false
|
||||||
resolver.deactivate = func(error) {
|
resolver.deactivate = func(error) {
|
||||||
|
lmux.Lock()
|
||||||
failed = true
|
failed = true
|
||||||
|
lmux.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
reactivated := false
|
reactivated := false
|
||||||
resolver.reactivate = func() {
|
resolver.reactivate = func() {
|
||||||
|
lmux.Lock()
|
||||||
reactivated = true
|
reactivated = true
|
||||||
|
lmux.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
resolver.ServeDNS(responseWriter, new(dns.Msg).SetQuestion("one.one.one.one.", dns.TypeA))
|
resolver.ServeDNS(responseWriter, new(dns.Msg).SetQuestion("one.one.one.one.", dns.TypeA))
|
||||||
|
lmux.Lock()
|
||||||
if !failed {
|
failedCheck := failed
|
||||||
|
lmux.Unlock()
|
||||||
|
if !failedCheck {
|
||||||
t.Errorf("expected that resolving was deactivated")
|
t.Errorf("expected that resolving was deactivated")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -160,7 +167,10 @@ func TestUpstreamResolver_DeactivationReactivation(t *testing.T) {
|
|||||||
|
|
||||||
time.Sleep(time.Millisecond * 200)
|
time.Sleep(time.Millisecond * 200)
|
||||||
|
|
||||||
if !reactivated {
|
lmux.Lock()
|
||||||
|
checkReactivated := reactivated
|
||||||
|
lmux.Unlock()
|
||||||
|
if !checkReactivated {
|
||||||
t.Errorf("expected that resolving was reactivated")
|
t.Errorf("expected that resolving was reactivated")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -836,7 +836,10 @@ func (e *Engine) updateSSH(sshConf *mgmProto.SSHConfig) error {
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
// blocking
|
// blocking
|
||||||
err = e.sshServer.Start()
|
e.syncMsgMux.Lock()
|
||||||
|
sshServer := e.sshServer
|
||||||
|
e.syncMsgMux.Unlock()
|
||||||
|
err = sshServer.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// will throw error when we stop it even if it is a graceful stop
|
// will throw error when we stop it even if it is a graceful stop
|
||||||
log.Debugf("stopped SSH server with error %v", err)
|
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) {
|
} else if !isNil(e.sshServer) {
|
||||||
// Disable SSH server request, so stop it if it was running
|
// Disable SSH server request, so stop it if it was running
|
||||||
|
e.syncMsgMux.Lock()
|
||||||
|
defer e.syncMsgMux.Unlock()
|
||||||
err := e.sshServer.Stop()
|
err := e.sshServer.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to stop SSH server %v", err)
|
log.Warnf("failed to stop SSH server %v", err)
|
||||||
|
|||||||
@@ -102,3 +102,11 @@ func (m *Manager) notify(peerConnID peerid.ConnID) {
|
|||||||
case m.OnActivityChan <- peerConnID:
|
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 {
|
if err := mgr.MonitorPeerActivity(peerCfg1); err != nil {
|
||||||
t.Fatalf("failed to monitor peer activity: %v", err)
|
t.Fatalf("failed to monitor peer activity: %v", err)
|
||||||
}
|
}
|
||||||
|
listener, ok := mgr.getPeerListener(peerCfg1.PeerConnID)
|
||||||
if err := trigger(mgr.peers[peerCfg1.PeerConnID].conn.LocalAddr().String()); err != nil {
|
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)
|
t.Fatalf("failed to trigger activity: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,30 +9,54 @@ type mocListener struct {
|
|||||||
lastState int
|
lastState int
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
peers int
|
peers int
|
||||||
|
mux sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *mocListener) OnConnected() {
|
func (l *mocListener) OnConnected() {
|
||||||
|
l.mux.Lock()
|
||||||
|
defer l.mux.Unlock()
|
||||||
l.lastState = stateConnected
|
l.lastState = stateConnected
|
||||||
l.wg.Done()
|
l.wg.Done()
|
||||||
}
|
}
|
||||||
func (l *mocListener) OnDisconnected() {
|
func (l *mocListener) OnDisconnected() {
|
||||||
|
l.mux.Lock()
|
||||||
|
defer l.mux.Unlock()
|
||||||
l.lastState = stateDisconnected
|
l.lastState = stateDisconnected
|
||||||
l.wg.Done()
|
l.wg.Done()
|
||||||
}
|
}
|
||||||
func (l *mocListener) OnConnecting() {
|
func (l *mocListener) OnConnecting() {
|
||||||
|
l.mux.Lock()
|
||||||
|
defer l.mux.Unlock()
|
||||||
l.lastState = stateConnecting
|
l.lastState = stateConnecting
|
||||||
l.wg.Done()
|
l.wg.Done()
|
||||||
}
|
}
|
||||||
func (l *mocListener) OnDisconnecting() {
|
func (l *mocListener) OnDisconnecting() {
|
||||||
|
l.mux.Lock()
|
||||||
|
defer l.mux.Unlock()
|
||||||
l.lastState = stateDisconnecting
|
l.lastState = stateDisconnecting
|
||||||
l.wg.Done()
|
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) OnAddressChanged(host, addr string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
func (l *mocListener) OnPeersListChanged(size int) {
|
func (l *mocListener) OnPeersListChanged(size int) {
|
||||||
|
l.mux.Lock()
|
||||||
l.peers = size
|
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() {
|
func (l *mocListener) setWaiter() {
|
||||||
@@ -77,7 +101,7 @@ func Test_notifier_SetListener(t *testing.T) {
|
|||||||
n.lastNotification = stateConnecting
|
n.lastNotification = stateConnecting
|
||||||
n.setListener(listener)
|
n.setListener(listener)
|
||||||
listener.wait()
|
listener.wait()
|
||||||
if listener.lastState != n.lastNotification {
|
if listener.getLastState() != n.lastNotification {
|
||||||
t.Errorf("invalid state: %d, expected: %d", listener.lastState, 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.removeListener()
|
||||||
n.peerListChanged(1)
|
n.peerListChanged(1)
|
||||||
|
|
||||||
if listener.peers != 0 {
|
if listener.getPeers() != 0 {
|
||||||
t.Errorf("invalid state: %d", listener.peers)
|
t.Errorf("invalid state: %d", listener.peers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -257,6 +257,6 @@ replace golang.zx2c4.com/wireguard => github.com/netbirdio/wireguard-go v0.0.0-2
|
|||||||
|
|
||||||
replace github.com/cloudflare/circl => github.com/cunicu/circl v0.0.0-20230801113412-fec58fc7b5f6
|
replace github.com/cloudflare/circl => github.com/cunicu/circl v0.0.0-20230801113412-fec58fc7b5f6
|
||||||
|
|
||||||
replace github.com/pion/ice/v3 => github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e
|
replace github.com/pion/ice/v3 => github.com/netbirdio/ice/v3 v3.0.0-20250718163601-725c8ac53a31
|
||||||
|
|
||||||
replace github.com/libp2p/go-netroute => github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944
|
replace github.com/libp2p/go-netroute => github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -501,8 +501,8 @@ github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJE
|
|||||||
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
|
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
|
||||||
github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944 h1:TDtJKmM6Sf8uYFx/dMeqNOL90KUoRscdfpFZ3Im89uk=
|
github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944 h1:TDtJKmM6Sf8uYFx/dMeqNOL90KUoRscdfpFZ3Im89uk=
|
||||||
github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944/go.mod h1:sHA6TRxjQ6RLbnI+3R4DZo2Eseg/iKiPRfNmcuNySVQ=
|
github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944/go.mod h1:sHA6TRxjQ6RLbnI+3R4DZo2Eseg/iKiPRfNmcuNySVQ=
|
||||||
github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e h1:PURA50S8u4mF6RrkYYCAvvPCixhqqEiEy3Ej6avh04c=
|
github.com/netbirdio/ice/v3 v3.0.0-20250718163601-725c8ac53a31 h1:lr/CnQ9NnlHr4yjDaCqy3V1FW+y9DDpzqxu1+YXzXtc=
|
||||||
github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e/go.mod h1:YMLU7qbKfVjmEv7EoZPIVEI+kNYxWCdPK3VS0BU+U4Q=
|
github.com/netbirdio/ice/v3 v3.0.0-20250718163601-725c8ac53a31/go.mod h1:YMLU7qbKfVjmEv7EoZPIVEI+kNYxWCdPK3VS0BU+U4Q=
|
||||||
github.com/netbirdio/management-integrations/integrations v0.0.0-20250718071730-f4d133556ff5 h1:Zfn8d83OVyELCdxgprcyXR3D8uqoxHtXE9PUxVXDx/w=
|
github.com/netbirdio/management-integrations/integrations v0.0.0-20250718071730-f4d133556ff5 h1:Zfn8d83OVyELCdxgprcyXR3D8uqoxHtXE9PUxVXDx/w=
|
||||||
github.com/netbirdio/management-integrations/integrations v0.0.0-20250718071730-f4d133556ff5/go.mod h1:Gi9raplYzCCyh07Olw/DVfCJTFgpr1WCXJ/Q+8TSA9Q=
|
github.com/netbirdio/management-integrations/integrations v0.0.0-20250718071730-f4d133556ff5/go.mod h1:Gi9raplYzCCyh07Olw/DVfCJTFgpr1WCXJ/Q+8TSA9Q=
|
||||||
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502 h1:3tHlFmhTdX9axERMVN63dqyFqnvuD+EMJHzM7mNGON8=
|
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502 h1:3tHlFmhTdX9axERMVN63dqyFqnvuD+EMJHzM7mNGON8=
|
||||||
|
|||||||
Reference in New Issue
Block a user