Skip to content

Commit 284b781

Browse files
committed
TestBufferedUpdates does not need a real db, altering test details slightly
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 2e16d76 commit 284b781

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

coderd/notifications/manager_test.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88
"time"
99

10+
"github.com/coder/coder/v2/coderd/database/pubsub"
1011
"github.com/google/uuid"
1112
"github.com/stretchr/testify/require"
1213
"golang.org/x/xerrors"
@@ -49,7 +50,9 @@ func TestBufferedUpdates(t *testing.T) {
4950
t.Parallel()
5051

5152
// setup
52-
ctx, logger, db, ps := setup(t)
53+
ctx := context.Background()
54+
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true, IgnoredErrorIs: []error{}}).Leveled(slog.LevelDebug)
55+
db := dbmem.New()
5356
interceptor := &bulkUpdateInterceptor{Store: db}
5457

5558
santa := &santaHandler{}
@@ -59,13 +62,16 @@ func TestBufferedUpdates(t *testing.T) {
5962
require.NoError(t, err)
6063
mgr.WithHandlers(handlers)
6164

62-
client := coderdtest.New(t, &coderdtest.Options{Database: db, Pubsub: ps})
65+
client := coderdtest.New(t, &coderdtest.Options{Database: db, Pubsub: pubsub.NewInMemory()})
6366
user := coderdtest.CreateFirstUser(t, client)
6467

6568
// given
6669
if _, err := mgr.Enqueue(ctx, user.UserID, notifications.TemplateWorkspaceDeleted, types.Labels{"nice": "true"}, ""); true {
6770
require.NoError(t, err)
6871
}
72+
if _, err := mgr.Enqueue(ctx, user.UserID, notifications.TemplateWorkspaceDeleted, types.Labels{"nice": "true"}, ""); true {
73+
require.NoError(t, err)
74+
}
6975
if _, err := mgr.Enqueue(ctx, user.UserID, notifications.TemplateWorkspaceDeleted, types.Labels{"nice": "false"}, ""); true {
7076
require.NoError(t, err)
7177
}
@@ -76,13 +82,13 @@ func TestBufferedUpdates(t *testing.T) {
7682
// then
7783

7884
// Wait for messages to be dispatched.
79-
require.Eventually(t, func() bool { return santa.naughty.Load() == 1 && santa.nice.Load() == 1 }, testutil.WaitMedium, testutil.IntervalFast)
85+
require.Eventually(t, func() bool { return santa.naughty.Load() == 1 && santa.nice.Load() == 2 }, testutil.WaitMedium, testutil.IntervalFast)
8086

8187
// Stop the manager which forces an update of buffered updates.
8288
require.NoError(t, mgr.Stop(ctx))
8389

8490
// Wait until both success & failure updates have been sent to the store.
85-
require.Eventually(t, func() bool { return interceptor.failed.Load() == 1 && interceptor.sent.Load() == 1 }, testutil.WaitMedium, testutil.IntervalFast)
91+
require.Eventually(t, func() bool { return interceptor.failed.Load() == 1 && interceptor.sent.Load() == 2 }, testutil.WaitMedium, testutil.IntervalFast)
8692
}
8793

8894
func TestBuildPayload(t *testing.T) {

0 commit comments

Comments
 (0)