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

Function TestProvisionerJob

cli/cliui/provisionerjob_test.go:26–204  ·  view source on GitHub ↗

This cannot be ran in parallel because it uses a signal. nolint:tparallel

(t *testing.T)

Source from the content-addressed store, hash-verified

24// This cannot be ran in parallel because it uses a signal.
25// nolint:tparallel
26func TestProvisionerJob(t *testing.T) {
27 t.Run("NoLogs", func(t *testing.T) {
28 t.Parallel()
29
30 test := newProvisionerJob(t)
31
32 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
33 defer cancel()
34
35 testutil.Go(t, func() {
36 <-test.Next
37 test.JobMutex.Lock()
38 test.Job.Status = codersdk.ProvisionerJobRunning
39 now := dbtime.Now()
40 test.Job.StartedAt = &now
41 test.JobMutex.Unlock()
42 <-test.Next
43 test.JobMutex.Lock()
44 test.Job.Status = codersdk.ProvisionerJobSucceeded
45 now = dbtime.Now()
46 test.Job.CompletedAt = &now
47 close(test.Logs)
48 test.JobMutex.Unlock()
49 })
50 testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
51 test.PTY.ExpectMatch(cliui.ProvisioningStateQueued)
52 test.Next <- struct{}{}
53 test.PTY.ExpectMatch(cliui.ProvisioningStateQueued)
54 test.PTY.ExpectMatch(cliui.ProvisioningStateRunning)
55 test.Next <- struct{}{}
56 test.PTY.ExpectMatch(cliui.ProvisioningStateRunning)
57 return true
58 }, testutil.IntervalFast)
59 })
60
61 t.Run("Stages", func(t *testing.T) {
62 t.Parallel()
63
64 test := newProvisionerJob(t)
65 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
66 defer cancel()
67
68 testutil.Go(t, func() {
69 <-test.Next
70 test.JobMutex.Lock()
71 test.Job.Status = codersdk.ProvisionerJobRunning
72 now := dbtime.Now()
73 test.Job.StartedAt = &now
74 test.Logs <- codersdk.ProvisionerJobLog{
75 CreatedAt: dbtime.Now(),
76 Stage: "Something",
77 }
78 test.JobMutex.Unlock()
79 <-test.Next
80 test.JobMutex.Lock()
81 test.Job.Status = codersdk.ProvisionerJobSucceeded
82 now = dbtime.Now()
83 test.Job.CompletedAt = &now

Callers

nothing calls this directly

Calls 12

GoFunction · 0.92
NowFunction · 0.92
EventuallyFunction · 0.92
newProvisionerJobFunction · 0.85
SkipMethod · 0.80
SkipNowMethod · 0.80
RunMethod · 0.65
SignalMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ExpectMatchMethod · 0.45
ExpectRegexMatchMethod · 0.45

Tested by

no test coverage detected