(t *testing.T)
| 31 | ) |
| 32 | |
| 33 | func TestRun(t *testing.T) { |
| 34 | t.Parallel() |
| 35 | |
| 36 | ctx := testutil.Context(t, testutil.WaitLong) |
| 37 | logger := testutil.Logger(t) |
| 38 | db, ps := dbtestutil.NewDB(t) |
| 39 | |
| 40 | inboxHandler := dispatch.NewInboxHandler(logger.Named("inbox"), db, ps) |
| 41 | |
| 42 | client := coderdtest.New(t, &coderdtest.Options{ |
| 43 | Database: db, |
| 44 | Pubsub: ps, |
| 45 | }) |
| 46 | firstUser := coderdtest.CreateFirstUser(t, client) |
| 47 | |
| 48 | const numReceivingUsers = 2 |
| 49 | const numRegularUsers = 2 |
| 50 | dialBarrier := new(sync.WaitGroup) |
| 51 | receivingWatchBarrier := new(sync.WaitGroup) |
| 52 | dialBarrier.Add(numReceivingUsers + numRegularUsers) |
| 53 | receivingWatchBarrier.Add(numReceivingUsers) |
| 54 | metrics := notifications.NewMetrics(prometheus.NewRegistry()) |
| 55 | |
| 56 | eg, runCtx := errgroup.WithContext(ctx) |
| 57 | |
| 58 | expectedNotificationsIDs := map[uuid.UUID]struct{}{ |
| 59 | notificationsLib.TemplateUserAccountCreated: {}, |
| 60 | notificationsLib.TemplateUserAccountDeleted: {}, |
| 61 | } |
| 62 | |
| 63 | // Start receiving runners who will receive notifications |
| 64 | receivingRunners := make([]*notifications.Runner, 0, numReceivingUsers) |
| 65 | for i := range numReceivingUsers { |
| 66 | runnerCfg := notifications.Config{ |
| 67 | User: createusers.Config{ |
| 68 | OrganizationID: firstUser.OrganizationID, |
| 69 | Username: "receiving-user-" + strconv.Itoa(i), |
| 70 | }, |
| 71 | Roles: []string{codersdk.RoleOwner}, |
| 72 | NotificationTimeout: testutil.WaitLong, |
| 73 | DialTimeout: testutil.WaitLong, |
| 74 | Metrics: metrics, |
| 75 | DialBarrier: dialBarrier, |
| 76 | ReceivingWatchBarrier: receivingWatchBarrier, |
| 77 | ExpectedNotificationsIDs: expectedNotificationsIDs, |
| 78 | } |
| 79 | err := runnerCfg.Validate() |
| 80 | require.NoError(t, err) |
| 81 | |
| 82 | runner := notifications.NewRunner(client, runnerCfg) |
| 83 | receivingRunners = append(receivingRunners, runner) |
| 84 | eg.Go(func() error { |
| 85 | return runner.Run(runCtx, "receiving-"+strconv.Itoa(i), io.Discard) |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | // Start regular user runners who will maintain websocket connections |
| 90 | regularRunners := make([]*notifications.Runner, 0, numRegularUsers) |
nothing calls this directly
no test coverage detected