MCPcopy Create free account
hub / github.com/coder/coder / Test_TestRun

Function Test_TestRun

scaletest/harness/run_test.go:53–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func Test_TestRun(t *testing.T) {
54 t.Parallel()
55
56 t.Run("OK", func(t *testing.T) {
57 t.Parallel()
58
59 var (
60 name, id = "test", "1"
61 runCalled atomic.Int64
62 cleanupCalled atomic.Int64
63 collectableCalled atomic.Int64
64
65 testFns = testFns{
66 RunFn: func(ctx context.Context, id string, logs io.Writer) error {
67 runCalled.Add(1)
68 return nil
69 },
70 CleanupFn: func(ctx context.Context, id string, logs io.Writer) error {
71 cleanupCalled.Add(1)
72 return nil
73 },
74 GetMetricsFn: func() map[string]any {
75 collectableCalled.Add(1)
76 return nil
77 },
78 }
79 )
80
81 run := harness.NewTestRun(name, id, testFns)
82 require.Equal(t, fmt.Sprintf("%s/%s", name, id), run.FullID())
83
84 err := run.Run(context.Background())
85 require.NoError(t, err)
86 require.EqualValues(t, 1, runCalled.Load())
87 require.EqualValues(t, 1, collectableCalled.Load())
88
89 err = run.Cleanup(context.Background())
90 require.NoError(t, err)
91 require.EqualValues(t, 1, cleanupCalled.Load())
92 })
93
94 t.Run("Cleanup", func(t *testing.T) {
95 t.Parallel()
96
97 t.Run("NoFn", func(t *testing.T) {
98 t.Parallel()
99
100 run := harness.NewTestRun("test", "1", testFns{
101 RunFn: func(ctx context.Context, id string, logs io.Writer) error {
102 return nil
103 },
104 CleanupFn: nil,
105 })
106
107 err := run.Cleanup(context.Background())
108 require.NoError(t, err)
109 })
110

Callers

nothing calls this directly

Calls 10

FullIDMethod · 0.95
RunMethod · 0.95
CleanupMethod · 0.95
ResultMethod · 0.95
NewTestRunFunction · 0.92
RunMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45
LoadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected