Skip to content

fix: avoid deleting peers on graceful close #14165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 14, 2024
Prev Previous commit
Next Next commit
extra checks
  • Loading branch information
sreya committed Aug 12, 2024
commit 159b509b0890886d29c9480a0894f900a84dbffa
19 changes: 17 additions & 2 deletions enterprise/tailnet/pgcoord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@ func TestPGCoordinator_NoDeleteOnClose(t *testing.T) {

err = coordinator.Close()
require.NoError(t, err)
assertEventuallyLost(ctx, t, store, agent.id)
assertEventuallyLost(ctx, t, store, client.id)

coordinator2, err := tailnet.NewPGCoord(ctx, logger, ps, store)
require.NoError(t, err)
Expand Down Expand Up @@ -974,6 +976,10 @@ func TestPGCoordinatorDual_FailedHeartbeat(t *testing.T) {
require.NoError(t, err)
p1.AssertEventuallyResponsesClosed()
p2.AssertEventuallyLost(p1.ID)
// This basically checks that peer2 had no update
// performed on their status since we are connected
// to coordinator2.
assertEventuallyStatus(ctx, t, store2, p2.ID, database.TailnetStatusOk)

// Connect peer1 to coordinator2.
p1.ConnectToCoordinator(ctx, c2)
Expand Down Expand Up @@ -1025,6 +1031,10 @@ func TestPGCoordinatorDual_PeerReconnect(t *testing.T) {
require.NoError(t, err)
p1.AssertEventuallyResponsesClosed()
p2.AssertEventuallyLost(p1.ID)
// This basically checks that peer2 had no update
// performed on their status since we are connected
// to coordinator2.
assertEventuallyStatus(ctx, t, store, p2.ID, database.TailnetStatusOk)

// Connect peer1 to coordinator2.
p1.ConnectToCoordinator(ctx, c2)
Expand Down Expand Up @@ -1178,7 +1188,7 @@ func assertNeverHasDERPs(ctx context.Context, t *testing.T, c *testConn, expecte
}
}

func assertEventuallyLost(ctx context.Context, t *testing.T, store database.Store, agentID uuid.UUID) {
func assertEventuallyStatus(ctx context.Context, t *testing.T, store database.Store, agentID uuid.UUID, status database.TailnetStatus) {
t.Helper()
assert.Eventually(t, func() bool {
peers, err := store.GetTailnetPeers(ctx, agentID)
Expand All @@ -1189,14 +1199,19 @@ func assertEventuallyLost(ctx context.Context, t *testing.T, store database.Stor
t.Fatal(err)
}
for _, peer := range peers {
if peer.Status == database.TailnetStatusOk {
if peer.Status != status {
return false
}
}
return true
}, testutil.WaitShort, testutil.IntervalFast)
}

func assertEventuallyLost(ctx context.Context, t *testing.T, store database.Store, agentID uuid.UUID) {
t.Helper()
assertEventuallyStatus(ctx, t, store, agentID, database.TailnetStatusLost)
}

func assertEventuallyNoClientsForAgent(ctx context.Context, t *testing.T, store database.Store, agentID uuid.UUID) {
t.Helper()
assert.Eventually(t, func() bool {
Expand Down
Loading