MCPcopy Index your code
hub / github.com/coder/coder / TestScriptReportsTiming

Function TestScriptReportsTiming

agent/agentscripts/agentscripts_test.go:119–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func 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.

Callers

nothing calls this directly

Calls 12

GetTimingsMethod · 0.95
ContextFunction · 0.92
NewFakeAgentAPIFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newFakeScriptLoggerFunction · 0.85
setupFunction · 0.70
InitMethod · 0.65
NewMethod · 0.65
ExecuteMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected