(t *testing.T)
| 117 | } |
| 118 | |
| 119 | func TestScriptReportsTiming(t *testing.T) { |
| 120 | t.Parallel() |
| 121 | |
| 122 | ctx := testutil.Context(t, testutil.WaitShort) |
| 123 | fLogger := newFakeScriptLogger() |
| 124 | runner := setup(t, func(uuid2 uuid.UUID) agentscripts.ScriptLogger { |
| 125 | return fLogger |
| 126 | }) |
| 127 | |
| 128 | aAPI := agenttest.NewFakeAgentAPI(t, testutil.Logger(t), nil, nil) |
| 129 | err := runner.Init([]codersdk.WorkspaceAgentScript{{ |
| 130 | DisplayName: "say-hello", |
| 131 | LogSourceID: uuid.New(), |
| 132 | Script: "echo hello", |
| 133 | }}, aAPI.ScriptCompleted) |
| 134 | require.NoError(t, err) |
| 135 | require.NoError(t, runner.Execute(ctx, agentscripts.ExecuteAllScripts)) |
| 136 | runner.Close() |
| 137 | |
| 138 | log := testutil.TryReceive(ctx, t, fLogger.logs) |
| 139 | require.Equal(t, "hello", log.Output) |
| 140 | |
| 141 | timings := aAPI.GetTimings() |
| 142 | require.Equal(t, 1, len(timings)) |
| 143 | |
| 144 | timing := timings[0] |
| 145 | require.Equal(t, int32(0), timing.ExitCode) |
| 146 | if assert.True(t, timing.Start.IsValid(), "start time should be valid") { |
| 147 | require.NotZero(t, timing.Start.AsTime(), "start time should not be zero") |
| 148 | } |
| 149 | if assert.True(t, timing.End.IsValid(), "end time should be valid") { |
| 150 | require.NotZero(t, timing.End.AsTime(), "end time should not be zero") |
| 151 | } |
| 152 | require.GreaterOrEqual(t, timing.End.AsTime(), timing.Start.AsTime()) |
| 153 | } |
| 154 | |
| 155 | // TestCronClose exists because cron.Run() can happen after cron.Close(). |
| 156 | // If this happens, there used to be a deadlock. |
nothing calls this directly
no test coverage detected