7
7
"testing"
8
8
"time"
9
9
10
+ "github.com/coder/coder/v2/coderd/database/pubsub"
10
11
"github.com/google/uuid"
11
12
"github.com/stretchr/testify/require"
12
13
"golang.org/x/xerrors"
@@ -49,7 +50,9 @@ func TestBufferedUpdates(t *testing.T) {
49
50
t .Parallel ()
50
51
51
52
// 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 ()
53
56
interceptor := & bulkUpdateInterceptor {Store : db }
54
57
55
58
santa := & santaHandler {}
@@ -59,13 +62,16 @@ func TestBufferedUpdates(t *testing.T) {
59
62
require .NoError (t , err )
60
63
mgr .WithHandlers (handlers )
61
64
62
- client := coderdtest .New (t , & coderdtest.Options {Database : db , Pubsub : ps })
65
+ client := coderdtest .New (t , & coderdtest.Options {Database : db , Pubsub : pubsub . NewInMemory () })
63
66
user := coderdtest .CreateFirstUser (t , client )
64
67
65
68
// given
66
69
if _ , err := mgr .Enqueue (ctx , user .UserID , notifications .TemplateWorkspaceDeleted , types.Labels {"nice" : "true" }, "" ); true {
67
70
require .NoError (t , err )
68
71
}
72
+ if _ , err := mgr .Enqueue (ctx , user .UserID , notifications .TemplateWorkspaceDeleted , types.Labels {"nice" : "true" }, "" ); true {
73
+ require .NoError (t , err )
74
+ }
69
75
if _ , err := mgr .Enqueue (ctx , user .UserID , notifications .TemplateWorkspaceDeleted , types.Labels {"nice" : "false" }, "" ); true {
70
76
require .NoError (t , err )
71
77
}
@@ -76,13 +82,13 @@ func TestBufferedUpdates(t *testing.T) {
76
82
// then
77
83
78
84
// 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 )
80
86
81
87
// Stop the manager which forces an update of buffered updates.
82
88
require .NoError (t , mgr .Stop (ctx ))
83
89
84
90
// 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 )
86
92
}
87
93
88
94
func TestBuildPayload (t * testing.T ) {
0 commit comments