mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
chore: update testutil chan helpers (#17408)
This commit is contained in:
@ -11,37 +11,3 @@ func Context(t *testing.T, dur time.Duration) context.Context {
|
||||
t.Cleanup(cancel)
|
||||
return ctx
|
||||
}
|
||||
|
||||
func RequireRecvCtx[A any](ctx context.Context, t testing.TB, c <-chan A) (a A) {
|
||||
t.Helper()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Fatal("timeout")
|
||||
return a
|
||||
case a = <-c:
|
||||
return a
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: no AssertRecvCtx because it'd be bad if we returned a default value on
|
||||
// the cases it times out.
|
||||
|
||||
func RequireSendCtx[A any](ctx context.Context, t testing.TB, c chan<- A, a A) {
|
||||
t.Helper()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Fatal("timeout")
|
||||
case c <- a:
|
||||
// OK!
|
||||
}
|
||||
}
|
||||
|
||||
func AssertSendCtx[A any](ctx context.Context, t testing.TB, c chan<- A, a A) {
|
||||
t.Helper()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Error("timeout")
|
||||
case c <- a:
|
||||
// OK!
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user