mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: update testutil chan helpers (#17408)
This commit is contained in:
@ -160,19 +160,19 @@ func TestPubSub_DoesntBlockNotify(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
cancels <- subCancel
|
||||
}()
|
||||
subCancel := testutil.RequireRecvCtx(ctx, t, cancels)
|
||||
subCancel := testutil.TryReceive(ctx, t, cancels)
|
||||
cancelDone := make(chan struct{})
|
||||
go func() {
|
||||
defer close(cancelDone)
|
||||
subCancel()
|
||||
}()
|
||||
testutil.RequireRecvCtx(ctx, t, cancelDone)
|
||||
testutil.TryReceive(ctx, t, cancelDone)
|
||||
|
||||
closeErrs := make(chan error)
|
||||
go func() {
|
||||
closeErrs <- uut.Close()
|
||||
}()
|
||||
err := testutil.RequireRecvCtx(ctx, t, closeErrs)
|
||||
err := testutil.TryReceive(ctx, t, closeErrs)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ func TestPubSub_DoesntRaceListenUnlisten(t *testing.T) {
|
||||
}
|
||||
close(start)
|
||||
for range numEvents * 2 {
|
||||
_ = testutil.RequireRecvCtx(ctx, t, done)
|
||||
_ = testutil.TryReceive(ctx, t, done)
|
||||
}
|
||||
for i := range events {
|
||||
fListener.requireIsListening(t, events[i])
|
||||
|
@ -60,7 +60,7 @@ func TestPGPubsub_Metrics(t *testing.T) {
|
||||
err := uut.Publish(event, []byte(data))
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
_ = testutil.RequireRecvCtx(ctx, t, messageChannel)
|
||||
_ = testutil.TryReceive(ctx, t, messageChannel)
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
latencyBytes := gatherCount * pubsub.LatencyMessageLength
|
||||
@ -96,8 +96,8 @@ func TestPGPubsub_Metrics(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
// should get 2 messages because we have 2 subs
|
||||
_ = testutil.RequireRecvCtx(ctx, t, messageChannel)
|
||||
_ = testutil.RequireRecvCtx(ctx, t, messageChannel)
|
||||
_ = testutil.TryReceive(ctx, t, messageChannel)
|
||||
_ = testutil.TryReceive(ctx, t, messageChannel)
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
latencyBytes := gatherCount * pubsub.LatencyMessageLength
|
||||
@ -167,10 +167,10 @@ func TestPGPubsubDriver(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// wait for the message
|
||||
_ = testutil.RequireRecvCtx(ctx, t, gotChan)
|
||||
_ = testutil.TryReceive(ctx, t, gotChan)
|
||||
|
||||
// read out first connection
|
||||
firstConn := testutil.RequireRecvCtx(ctx, t, subDriver.Connections)
|
||||
firstConn := testutil.TryReceive(ctx, t, subDriver.Connections)
|
||||
|
||||
// drop the underlying connection being used by the pubsub
|
||||
// the pq.Listener should reconnect and repopulate it's listeners
|
||||
@ -179,7 +179,7 @@ func TestPGPubsubDriver(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// wait for the reconnect
|
||||
_ = testutil.RequireRecvCtx(ctx, t, subDriver.Connections)
|
||||
_ = testutil.TryReceive(ctx, t, subDriver.Connections)
|
||||
// we need to sleep because the raw connection notification
|
||||
// is sent before the pq.Listener can reestablish it's listeners
|
||||
time.Sleep(1 * time.Second)
|
||||
@ -189,5 +189,5 @@ func TestPGPubsubDriver(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// wait for the message on the old subscription
|
||||
_ = testutil.RequireRecvCtx(ctx, t, gotChan)
|
||||
_ = testutil.TryReceive(ctx, t, gotChan)
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func TestWatchdog_NoTimeout(t *testing.T) {
|
||||
|
||||
// we subscribe after starting the timer, so we know the timer also starts
|
||||
// from the baseline.
|
||||
sub := testutil.RequireRecvCtx(ctx, t, fPS.subs)
|
||||
sub := testutil.TryReceive(ctx, t, fPS.subs)
|
||||
require.Equal(t, pubsub.EventPubsubWatchdog, sub.event)
|
||||
|
||||
// 5 min / 15 sec = 20, so do 21 ticks
|
||||
@ -45,7 +45,7 @@ func TestWatchdog_NoTimeout(t *testing.T) {
|
||||
d, w := mClock.AdvanceNext()
|
||||
w.MustWait(ctx)
|
||||
require.LessOrEqual(t, d, 15*time.Second)
|
||||
p := testutil.RequireRecvCtx(ctx, t, fPS.pubs)
|
||||
p := testutil.TryReceive(ctx, t, fPS.pubs)
|
||||
require.Equal(t, pubsub.EventPubsubWatchdog, p)
|
||||
mClock.Advance(30 * time.Millisecond). // reasonable round-trip
|
||||
MustWait(ctx)
|
||||
@ -67,7 +67,7 @@ func TestWatchdog_NoTimeout(t *testing.T) {
|
||||
sc, err := subTrap.Wait(ctx) // timer.Stop() called
|
||||
require.NoError(t, err)
|
||||
sc.Release()
|
||||
err = testutil.RequireRecvCtx(ctx, t, errCh)
|
||||
err = testutil.TryReceive(ctx, t, errCh)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ func TestWatchdog_Timeout(t *testing.T) {
|
||||
|
||||
// we subscribe after starting the timer, so we know the timer also starts
|
||||
// from the baseline.
|
||||
sub := testutil.RequireRecvCtx(ctx, t, fPS.subs)
|
||||
sub := testutil.TryReceive(ctx, t, fPS.subs)
|
||||
require.Equal(t, pubsub.EventPubsubWatchdog, sub.event)
|
||||
|
||||
// 5 min / 15 sec = 20, so do 19 ticks without timing out
|
||||
@ -101,7 +101,7 @@ func TestWatchdog_Timeout(t *testing.T) {
|
||||
d, w := mClock.AdvanceNext()
|
||||
w.MustWait(ctx)
|
||||
require.LessOrEqual(t, d, 15*time.Second)
|
||||
p := testutil.RequireRecvCtx(ctx, t, fPS.pubs)
|
||||
p := testutil.TryReceive(ctx, t, fPS.pubs)
|
||||
require.Equal(t, pubsub.EventPubsubWatchdog, p)
|
||||
mClock.Advance(30 * time.Millisecond). // reasonable round-trip
|
||||
MustWait(ctx)
|
||||
@ -117,9 +117,9 @@ func TestWatchdog_Timeout(t *testing.T) {
|
||||
d, w := mClock.AdvanceNext()
|
||||
w.MustWait(ctx)
|
||||
require.LessOrEqual(t, d, 15*time.Second)
|
||||
p := testutil.RequireRecvCtx(ctx, t, fPS.pubs)
|
||||
p := testutil.TryReceive(ctx, t, fPS.pubs)
|
||||
require.Equal(t, pubsub.EventPubsubWatchdog, p)
|
||||
testutil.RequireRecvCtx(ctx, t, uut.Timeout())
|
||||
testutil.TryReceive(ctx, t, uut.Timeout())
|
||||
|
||||
err = uut.Close()
|
||||
require.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user