Skip to content

Commit 5abde6d

Browse files
committed
test enqeueue multiple
1 parent 98f3b17 commit 5abde6d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

coderd/notifications/notifications_test.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,16 +2152,27 @@ func TestNotificationEnqueuePubsubNotify(t *testing.T) {
21522152
mgr.Run(ctx)
21532153
fetchTrap.MustWait(ctx).Release()
21542154

2155-
// When: a notification is enqueued
2156-
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{}, "test")
2157-
require.NoError(t, err)
2155+
// When: a number of notifications are enqueued
2156+
const numEnqueued = 10
2157+
for i := range numEnqueued {
2158+
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"i": fmt.Sprintf("%d", i)}, fmt.Sprintf("test %d", i))
2159+
require.NoError(t, err)
2160+
}
21582161

21592162
// Then: we attempt to dispatch the notification immediately.
2160-
call := testutil.TryReceive(ctx, t, handler.calls)
2161-
testutil.RequireSend(ctx, t, call.result, dispatchResult{
2162-
retryable: false,
2163-
err: nil,
2164-
})
2163+
recvDone := make(chan struct{})
2164+
go func() {
2165+
defer close(recvDone)
2166+
for range numEnqueued {
2167+
call := testutil.TryReceive(ctx, t, handler.calls)
2168+
<-time.After(testutil.IntervalFast) // Simulate some processing time.
2169+
testutil.RequireSend(ctx, t, call.result, dispatchResult{
2170+
retryable: false,
2171+
err: nil,
2172+
})
2173+
}
2174+
}()
2175+
_ = testutil.TryReceive(ctx, t, recvDone)
21652176
}
21662177

21672178
type fakeHandler struct {

coderd/notifications/notifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (n *notifier) run(success chan<- dispatchResult, failure chan<- dispatchRes
153153
return
154154
// This is a no-op if the notifier is paused.
155155
case loopTick <- c:
156-
<-c // Wait for the processing loop to finish.
156+
// We do not wait for the processing loop to finish here.
157157
default:
158158
// If the loop is busy, don't send a notification.
159159
n.log.Debug(ctx, "notifier busy, skipping notification")

0 commit comments

Comments
 (0)