Skip to content

test: fix TestAgent_Lifecycle/ShutdownScriptOnce to wait for stats #17387

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1650,8 +1650,10 @@ func TestAgent_Lifecycle(t *testing.T) {
t.Run("ShutdownScriptOnce", func(t *testing.T) {
t.Parallel()
logger := testutil.Logger(t)
ctx := testutil.Context(t, testutil.WaitMedium)
expected := "this-is-shutdown"
derpMap, _ := tailnettest.RunDERPAndSTUN(t)
statsCh := make(chan *proto.Stats, 50)

client := agenttest.NewClient(t,
logger,
Expand All @@ -1670,7 +1672,7 @@ func TestAgent_Lifecycle(t *testing.T) {
RunOnStop: true,
}},
},
make(chan *proto.Stats, 50),
statsCh,
tailnet.NewCoordinator(logger),
)
defer client.Close()
Expand All @@ -1695,6 +1697,11 @@ func TestAgent_Lifecycle(t *testing.T) {
return len(content) > 0 // something is in the startup log file
}, testutil.WaitShort, testutil.IntervalMedium)

// In order to avoid shutting down the agent before it is fully started and triggering
// errors, we'll wait until the agent is fully up. It's a bit hokey, but among the last things the agent starts
// is the stats reporting, so getting a stats report is a good indication the agent is fully up.
_ = testutil.RequireRecvCtx(ctx, t, statsCh)

err := agent.Close()
require.NoError(t, err, "agent should be closed successfully")

Expand Down
Loading