Skip to content

Commit c88e416

Browse files
authored
fix: TestPendingUpdatesMetric flake (coder#13944)
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 492ab1c commit c88e416

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

coderd/notifications/metrics_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package notifications_test
22

33
import (
44
"context"
5-
"sync"
65
"testing"
76
"time"
87

@@ -260,7 +259,7 @@ func TestPendingUpdatesMetric(t *testing.T) {
260259
require.EqualValues(t, pending, success+failure)
261260

262261
// Unpause the interceptor so the updates can proceed.
263-
interceptor.proceed.Broadcast()
262+
interceptor.unpause()
264263

265264
// Validate that the store synced the expected number of updates.
266265
require.Eventually(t, func() bool {
@@ -376,7 +375,7 @@ func fingerprintLabels(lbs ...string) model.Fingerprint {
376375
type updateSignallingInterceptor struct {
377376
notifications.Store
378377

379-
proceed *sync.Cond
378+
pause chan any
380379

381380
updateSuccess chan int
382381
updateFailure chan int
@@ -386,33 +385,31 @@ func newUpdateSignallingInterceptor(interceptor notifications.Store) *updateSign
386385
return &updateSignallingInterceptor{
387386
Store: interceptor,
388387

389-
proceed: sync.NewCond(&sync.Mutex{}),
388+
pause: make(chan any, 1),
390389

391390
updateSuccess: make(chan int, 1),
392391
updateFailure: make(chan int, 1),
393392
}
394393
}
395394

395+
func (u *updateSignallingInterceptor) unpause() {
396+
close(u.pause)
397+
}
398+
396399
func (u *updateSignallingInterceptor) BulkMarkNotificationMessagesSent(ctx context.Context, arg database.BulkMarkNotificationMessagesSentParams) (int64, error) {
397400
u.updateSuccess <- len(arg.IDs)
398401

399-
u.proceed.L.Lock()
400-
defer u.proceed.L.Unlock()
401-
402402
// Wait until signaled so we have a chance to read the number of pending updates.
403-
u.proceed.Wait()
403+
<-u.pause
404404

405405
return u.Store.BulkMarkNotificationMessagesSent(ctx, arg)
406406
}
407407

408408
func (u *updateSignallingInterceptor) BulkMarkNotificationMessagesFailed(ctx context.Context, arg database.BulkMarkNotificationMessagesFailedParams) (int64, error) {
409409
u.updateFailure <- len(arg.IDs)
410410

411-
u.proceed.L.Lock()
412-
defer u.proceed.L.Unlock()
413-
414411
// Wait until signaled so we have a chance to read the number of pending updates.
415-
u.proceed.Wait()
412+
<-u.pause
416413

417414
return u.Store.BulkMarkNotificationMessagesFailed(ctx, arg)
418415
}

0 commit comments

Comments
 (0)