mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
Adds support to Coordination to call SetAllPeersLost() when it is closed. This ensure that when we disconnect from a Coordinator, we set all peers lost. This covers CoderSDK (CLI client) and Agent. Next PR will cover MultiAgent (notably, `wsproxy`).
35 lines
581 B
Go
35 lines
581 B
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func Context(t *testing.T, dur time.Duration) context.Context {
|
|
ctx, cancel := context.WithTimeout(context.Background(), dur)
|
|
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
|
|
}
|
|
}
|
|
|
|
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!
|
|
}
|
|
}
|