-
Notifications
You must be signed in to change notification settings - Fork 943
feat: implement thin vertical slice of system-generated notifications #13537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
53c9cbb
4856aed
cda6efb
86f937a
e8f1af2
a056f54
8c64d30
ac149ec
884fadf
4e362e7
8097290
1b841ad
61f5bd6
3c8e33b
757327c
6f909ae
36698c5
c5701a6
9d4c312
9380d8e
4b7214d
6679ef1
337997d
ba5f7c6
0f29293
7c6c486
c6e75c2
aff9e6c
613e074
faea7fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ightly Signed-off-by: Danny Kopping <danny@coder.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/coder/coder/v2/coderd/database/pubsub" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/xerrors" | ||
|
@@ -49,7 +50,9 @@ func TestBufferedUpdates(t *testing.T) { | |
t.Parallel() | ||
|
||
// setup | ||
ctx, logger, db, ps := setup(t) | ||
ctx := context.Background() | ||
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true, IgnoredErrorIs: []error{}}).Leveled(slog.LevelDebug) | ||
db := dbmem.New() | ||
interceptor := &bulkUpdateInterceptor{Store: db} | ||
|
||
santa := &santaHandler{} | ||
|
@@ -59,13 +62,16 @@ func TestBufferedUpdates(t *testing.T) { | |
require.NoError(t, err) | ||
mgr.WithHandlers(handlers) | ||
|
||
client := coderdtest.New(t, &coderdtest.Options{Database: db, Pubsub: ps}) | ||
client := coderdtest.New(t, &coderdtest.Options{Database: db, Pubsub: pubsub.NewInMemory()}) | ||
user := coderdtest.CreateFirstUser(t, client) | ||
|
||
// given | ||
if _, err := mgr.Enqueue(ctx, user.UserID, notifications.TemplateWorkspaceDeleted, types.Labels{"nice": "true"}, ""); true { | ||
require.NoError(t, err) | ||
} | ||
if _, err := mgr.Enqueue(ctx, user.UserID, notifications.TemplateWorkspaceDeleted, types.Labels{"nice": "true"}, ""); true { | ||
require.NoError(t, err) | ||
} | ||
if _, err := mgr.Enqueue(ctx, user.UserID, notifications.TemplateWorkspaceDeleted, types.Labels{"nice": "false"}, ""); true { | ||
require.NoError(t, err) | ||
} | ||
|
@@ -76,13 +82,13 @@ func TestBufferedUpdates(t *testing.T) { | |
// then | ||
|
||
// Wait for messages to be dispatched. | ||
require.Eventually(t, func() bool { return santa.naughty.Load() == 1 && santa.nice.Load() == 1 }, testutil.WaitMedium, testutil.IntervalFast) | ||
require.Eventually(t, func() bool { return santa.naughty.Load() == 1 && santa.nice.Load() == 2 }, testutil.WaitMedium, testutil.IntervalFast) | ||
|
||
// Stop the manager which forces an update of buffered updates. | ||
require.NoError(t, mgr.Stop(ctx)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a race condition here, which is that above we wait for notifications to be sent to santa, but sending to santa happens before sending on the Quartz can help here. The manager's bulk update and the notifier's processing loop depend on Tickers. If you convert them to use a This lets us get rid of the It also means we can get rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've got a follow-up item to implement Quartz in a subsequent PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 613e074 |
||
|
||
// Wait until both success & failure updates have been sent to the store. | ||
require.Eventually(t, func() bool { return interceptor.failed.Load() == 1 && interceptor.sent.Load() == 1 }, testutil.WaitMedium, testutil.IntervalFast) | ||
require.Eventually(t, func() bool { return interceptor.failed.Load() == 1 && interceptor.sent.Load() == 2 }, testutil.WaitMedium, testutil.IntervalFast) | ||
} | ||
|
||
func TestBuildPayload(t *testing.T) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.