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

Function TestCloserStack_CloseAfterContext

cli/ssh_internal_test.go:154–185  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func TestCloserStack_CloseAfterContext(t *testing.T) {
155 t.Parallel()
156 testCtx := testutil.Context(t, testutil.WaitShort)
157 ctx, cancel := context.WithCancel(testCtx)
158 defer cancel()
159 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
160 uut := newCloserStack(ctx, logger, quartz.NewMock(t))
161 ac := newAsyncCloser(testCtx, t)
162 defer ac.unblock()
163 err := uut.push("async", ac)
164 require.NoError(t, err)
165 cancel()
166 testutil.TryReceive(testCtx, t, ac.started)
167
168 closed := make(chan struct{})
169 go func() {
170 defer close(closed)
171 uut.close(nil)
172 }()
173
174 // since the asyncCloser is still waiting, we shouldn't complete uut.close()
175 select {
176 case <-time.After(testutil.IntervalFast):
177 // OK!
178 case <-closed:
179 t.Fatal("closed before stack was finished")
180 }
181
182 ac.unblock()
183 testutil.TryReceive(testCtx, t, closed)
184 testutil.TryReceive(testCtx, t, ac.done)
185}
186
187func TestCloserStack_Timeout(t *testing.T) {
188 t.Parallel()

Callers

nothing calls this directly

Calls 8

ContextFunction · 0.92
TryReceiveFunction · 0.92
newCloserStackFunction · 0.85
newAsyncCloserFunction · 0.85
unblockMethod · 0.80
pushMethod · 0.80
FatalMethod · 0.80
closeMethod · 0.65

Tested by

no test coverage detected