fix tests

This commit is contained in:
bcmmbaga 2024-08-16 12:24:06 +03:00
parent 8826196503
commit f29f8c009f
No known key found for this signature in database
GPG Key ID: 7249A19D20613553
13 changed files with 57 additions and 61 deletions

View File

@ -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")
}
}

View File

@ -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")
}
})

View File

@ -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")
}
})

View File

@ -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")
}
})

View File

@ -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

View File

@ -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")
}
})

View File

@ -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")
}

View File

@ -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
}

View File

@ -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")
}
})

View File

@ -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")
}
})

View File

@ -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")
}
})

View File

@ -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 {

View File

@ -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")
}
})