Files
coder/testutil/ctx.go
Spike Curtis f400d8a0c5 fix: handle SIGHUP from OpenSSH (#10638)
Fixes an issue where remote forwards are not correctly torn down when using OpenSSH with `coder ssh --stdio`.  OpenSSH sends a disconnect signal, but then also sends SIGHUP to `coder`.  Previously, we just exited when we got SIGHUP, and this raced against properly disconnecting.

Fixes https://github.com/coder/customers/issues/327
2023-11-13 15:14:42 +04:00

25 lines
408 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
}
}