mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
test: fix TestAgent_Lifecycle/ShutdownScriptOnce to wait for stats (#17387)
fixes: https://github.com/coder/internal/issues/576 TestAgent_Lifecycle/ShutdownScriptOnce hits error logs which cause test failures. These logs are legit errors and have to do with shutting down the agent before it has fully come up. This PR changes the test to wait for the agent to send stats (a good indicator that it's fully up, and beyond the errors that have triggered test failures in past) before closing it.
This commit is contained in:
@ -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,
|
||||
@ -1670,7 +1672,7 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
RunOnStop: true,
|
||||
}},
|
||||
},
|
||||
make(chan *proto.Stats, 50),
|
||||
statsCh,
|
||||
tailnet.NewCoordinator(logger),
|
||||
)
|
||||
defer client.Close()
|
||||
@ -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")
|
||||
|
||||
|
Reference in New Issue
Block a user