diff --git a/management/server/account_test.go b/management/server/account_test.go index 6067beb3d..73b490b4e 100644 --- a/management/server/account_test.go +++ b/management/server/account_test.go @@ -2444,7 +2444,7 @@ func peerShouldNotReceiveUpdate(t *testing.T, updateMessage <-chan *UpdateMessag select { case msg := <-updateMessage: t.Errorf("Unexpected message received: %+v", msg) - case <-time.After(100 * time.Millisecond): + case <-time.After(500 * time.Millisecond): return } } @@ -2453,9 +2453,11 @@ func peerShouldReceiveUpdate(t *testing.T, updateMessage <-chan *UpdateMessage) t.Helper() select { - case <-updateMessage: - return - case <-time.After(100 * time.Millisecond): - t.Errorf("timed out waiting for update message") + case msg := <-updateMessage: + if msg == nil { + t.Errorf("Received nil update message, expected valid message") + } + case <-time.After(500 * time.Millisecond): + t.Error("Timed out waiting for update message") } } diff --git a/management/server/dns_test.go b/management/server/dns_test.go index a861f6d34..c06ee1679 100644 --- a/management/server/dns_test.go +++ b/management/server/dns_test.go @@ -509,7 +509,7 @@ func TestDNSAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -540,7 +540,7 @@ func TestDNSAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -561,7 +561,7 @@ func TestDNSAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) diff --git a/management/server/group_test.go b/management/server/group_test.go index 83ac1c904..d83182a31 100644 --- a/management/server/group_test.go +++ b/management/server/group_test.go @@ -418,7 +418,7 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -436,7 +436,7 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -454,7 +454,7 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -472,7 +472,7 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -510,7 +510,7 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -533,7 +533,7 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -551,13 +551,13 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) - // removing peer to a used group should update account peers and send peer update - t.Run("removing peer to unused group", func(t *testing.T) { + // removing peer from a used group should update account peers and send peer update + t.Run("removing peer from used group", func(t *testing.T) { done := make(chan struct{}) go func() { peerShouldReceiveUpdate(t, updMsg) @@ -569,7 +569,7 @@ func TestGroupAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) diff --git a/management/server/nameserver_test.go b/management/server/nameserver_test.go index 4107695ab..cbc3fdee0 100644 --- a/management/server/nameserver_test.go +++ b/management/server/nameserver_test.go @@ -977,7 +977,7 @@ func TestNameServerAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -998,7 +998,7 @@ func TestNameServerAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) diff --git a/management/server/peer.go b/management/server/peer.go index e6919a60d..be58ae684 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -220,7 +220,6 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user } account.UpdatePeer(peer) - account.Network.IncSerial() err = am.Store.SaveAccount(ctx, account) if err != nil { return nil, err diff --git a/management/server/peer_test.go b/management/server/peer_test.go index c93b98c8e..102923e37 100644 --- a/management/server/peer_test.go +++ b/management/server/peer_test.go @@ -1010,11 +1010,6 @@ func TestPeerAccountPeerUpdate(t *testing.T) { }) require.NoError(t, err) - updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID) - t.Cleanup(func() { - manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID) - }) - // create a user with auto groups _, err = manager.SaveOrAddUser(context.Background(), account.Id, userID, &User{ Id: "regularUser1", @@ -1027,6 +1022,11 @@ func TestPeerAccountPeerUpdate(t *testing.T) { var peer4 *nbpeer.Peer + updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID) + t.Cleanup(func() { + manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID) + }) + // Updating not expired peer and peer expiration is enabled should not update account peers and not send peer update t.Run("updating not expired peer and peer expiration is enabled", func(t *testing.T) { done := make(chan struct{}) @@ -1040,7 +1040,7 @@ func TestPeerAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -1065,7 +1065,7 @@ func TestPeerAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -1083,7 +1083,7 @@ func TestPeerAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -1125,7 +1125,7 @@ func TestPeerAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -1143,7 +1143,7 @@ func TestPeerAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) diff --git a/management/server/policy_test.go b/management/server/policy_test.go index 2ff16f51f..366cb3d74 100644 --- a/management/server/policy_test.go +++ b/management/server/policy_test.go @@ -868,7 +868,7 @@ func TestPolicyAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -896,7 +896,7 @@ func TestPolicyAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -915,7 +915,7 @@ func TestPolicyAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -933,7 +933,7 @@ func TestPolicyAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } diff --git a/management/server/posture_checks.go b/management/server/posture_checks.go index cb9aae49d..5bad42f4e 100644 --- a/management/server/posture_checks.go +++ b/management/server/posture_checks.go @@ -73,9 +73,9 @@ func (am *DefaultAccountManager) SavePostureChecks(ctx context.Context, accountI action := activity.PostureCheckCreated if exists { action = activity.PostureCheckUpdated + account.Network.IncSerial() } - account.Network.IncSerial() if err = am.Store.SaveAccount(ctx, account); err != nil { return err } diff --git a/management/server/posture_checks_test.go b/management/server/posture_checks_test.go index 8b9cba671..439d1a2e7 100644 --- a/management/server/posture_checks_test.go +++ b/management/server/posture_checks_test.go @@ -131,11 +131,6 @@ func TestPostureCheckAccountPeerUpdate(t *testing.T) { }) assert.NoError(t, err) - updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID) - t.Cleanup(func() { - manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID) - }) - postureCheck := posture.Checks{ ID: "versionCheck", Name: "Version Check", @@ -148,6 +143,11 @@ func TestPostureCheckAccountPeerUpdate(t *testing.T) { }, } + updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID) + t.Cleanup(func() { + manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID) + }) + // Saving unused posture check should not update account peers and not send peer update t.Run("saving unused posture check", func(t *testing.T) { done := make(chan struct{}) @@ -159,10 +159,9 @@ func TestPostureCheckAccountPeerUpdate(t *testing.T) { err := manager.SavePostureChecks(context.Background(), account.Id, userID, &postureCheck) assert.NoError(t, err) - // wait for goroutine select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -195,7 +194,7 @@ func TestPostureCheckAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } @@ -218,10 +217,9 @@ func TestPostureCheckAccountPeerUpdate(t *testing.T) { err := manager.SavePostureChecks(context.Background(), account.Id, userID, &postureCheck) assert.NoError(t, err) - // wait for goroutine select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -238,10 +236,9 @@ func TestPostureCheckAccountPeerUpdate(t *testing.T) { err := manager.SavePostureChecks(context.Background(), account.Id, userID, &postureCheck) assert.NoError(t, err) - // wait for goroutine select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -259,10 +256,9 @@ func TestPostureCheckAccountPeerUpdate(t *testing.T) { err := manager.SavePolicy(context.Background(), account.Id, userID, &policy) assert.NoError(t, err) - // wait for goroutine select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) diff --git a/management/server/route_test.go b/management/server/route_test.go index e1332fc72..8dcdef884 100644 --- a/management/server/route_test.go +++ b/management/server/route_test.go @@ -1507,7 +1507,7 @@ func TestRouteAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -1527,7 +1527,7 @@ func TestRouteAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -1545,7 +1545,7 @@ func TestRouteAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) diff --git a/management/server/setupkey_test.go b/management/server/setupkey_test.go index 7855c52d2..b049b53ab 100644 --- a/management/server/setupkey_test.go +++ b/management/server/setupkey_test.go @@ -400,7 +400,7 @@ func TestSetupKeyAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -418,7 +418,7 @@ func TestSetupKeyAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) diff --git a/management/server/updatechannel.go b/management/server/updatechannel.go index 939b8e5db..68e694893 100644 --- a/management/server/updatechannel.go +++ b/management/server/updatechannel.go @@ -238,7 +238,6 @@ func isNewPeerUpdateMessage(lastSentUpdate, currUpdateToSend *UpdateMessage) (bo } differ, err := diff.NewDiffer( - diff.SliceOrdering(true), diff.CustomValueDiffers(differs.NewNameServerComparator(), differs.NewRouteComparator()), ) if err != nil { diff --git a/management/server/user_test.go b/management/server/user_test.go index 9b387f757..f5a26ef89 100644 --- a/management/server/user_test.go +++ b/management/server/user_test.go @@ -1301,7 +1301,7 @@ func TestUserAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -1324,7 +1324,7 @@ func TestUserAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -1342,7 +1342,7 @@ func TestUserAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldNotReceiveUpdate") } }) @@ -1384,7 +1384,7 @@ func TestUserAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } }) @@ -1409,7 +1409,7 @@ func TestUserAccountPeerUpdate(t *testing.T) { select { case <-done: - case <-time.After(200 * time.Millisecond): + case <-time.After(time.Second): t.Error("timeout waiting for peerShouldReceiveUpdate") } })