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

Function AssertReceive

testutil/chan.go:88–101  ·  view source on GitHub ↗

AssertReceive will receive a value from the chan and return it. If the context expires or the channel is closed before a value can be received, it will mark the test as failed but continue execution. The second return value indicates whether the receive was successful. Safety: can be called from an

(ctx context.Context, t testing.TB, c <-chan A)

Source from the content-addressed store, hash-verified

86//
87// Safety: can be called from any goroutine.
88func AssertReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, bool) {
89 t.Helper()
90 select {
91 case <-ctx.Done():
92 assert.Fail(t, "AssertReceive: context expired")
93 var a A
94 return a, false
95 case a, ok := <-c:
96 if !ok {
97 assert.Fail(t, "AssertReceive: channel closed")
98 }
99 return a, ok
100 }
101}
102
103// AssertSend will send the given value over the chan and then return. If
104// the context expires before the send succeeds, it will mark the test as failed

Callers

nothing calls this directly

Calls 3

HelperMethod · 0.65
DoneMethod · 0.45
FailMethod · 0.45

Tested by

no test coverage detected