@@ -2060,89 +2060,16 @@ func (r *RootCmd) scaletestNotifications() *serpent.Command {
2060
2060
configs = append (configs ,config )
2061
2061
}
2062
2062
2063
- go func () {
2064
- logger .Info (ctx ,"waiting for owner users to connect" )
2065
-
2066
- // Wait for owner users to connect
2067
- ownerWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
2068
- defer cancel ()
2069
-
2070
- ownerDone := make (chan struct {})
2071
- go func () {
2072
- ownerDialBarrier .Wait ()
2073
- close (ownerDone )
2074
- }()
2075
-
2076
- select {
2077
- case <- ownerDone :
2078
- logger .Info (ctx ,"all owner users connected" )
2079
- case <- ownerWaitCtx .Done ():
2080
- if ownerWaitCtx .Err ()== context .DeadlineExceeded {
2081
- logger .Error (ctx ,"timeout waiting for owner users to connect" )
2082
- }else {
2083
- logger .Info (ctx ,"context canceled while waiting for owner users" )
2084
- }
2085
- return
2086
- }
2087
-
2088
- // Wait for regular users to connect
2089
- logger .Info (ctx ,"waiting for regular users to connect" )
2090
- regularWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
2091
- defer cancel ()
2092
-
2093
- regularDone := make (chan struct {})
2094
- go func () {
2095
- regularDialBarrier .Wait ()
2096
- close (regularDone )
2097
- }()
2098
-
2099
- select {
2100
- case <- regularDone :
2101
- logger .Info (ctx ,"all regular users connected" )
2102
- case <- regularWaitCtx .Done ():
2103
- if regularWaitCtx .Err ()== context .DeadlineExceeded {
2104
- logger .Error (ctx ,"timeout waiting for regular users to connect" )
2105
- }else {
2106
- logger .Info (ctx ,"context canceled while waiting for regular users" )
2107
- }
2108
- return
2109
- }
2110
-
2111
- logger .Info (ctx ,"all users connected, triggering notifications" )
2112
-
2113
- const (
2114
- triggerUsername = "scaletest-trigger-user"
2115
- triggerEmail = "scaletest-trigger@example.com"
2116
- )
2117
-
2118
- logger .Info (ctx ,"creating test user to test notifications" ,
2119
- slog .F ("username" ,triggerUsername ),
2120
- slog .F ("email" ,triggerEmail ),
2121
- slog .F ("org_id" ,me .OrganizationIDs [0 ]))
2122
-
2123
- createTime := time .Now ()
2124
- testUser ,err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
2125
- OrganizationIDs : []uuid.UUID {me .OrganizationIDs [0 ]},
2126
- Username :triggerUsername ,
2127
- Email :triggerEmail ,
2128
- Password :"test-password-123" ,
2129
- })
2130
- if err != nil {
2131
- logger .Error (ctx ,"create test user" ,slog .Error (err ))
2132
- return
2133
- }
2134
- expectedNotifications [notificationsLib .TemplateUserAccountCreated ]<- createTime
2135
-
2136
- deleteTime := time .Now ()
2137
- err = client .DeleteUser (ctx ,testUser .ID )
2138
- if err != nil {
2139
- logger .Error (ctx ,"delete test user" ,slog .Error (err ))
2140
- return
2141
- }
2142
- expectedNotifications [notificationsLib .TemplateUserAccountDeleted ]<- deleteTime
2143
- close (expectedNotifications [notificationsLib .TemplateUserAccountCreated ])
2144
- close (expectedNotifications [notificationsLib .TemplateUserAccountDeleted ])
2145
- }()
2063
+ go triggerUserNotifications (
2064
+ ctx ,
2065
+ logger ,
2066
+ client ,
2067
+ me .OrganizationIDs [0 ],
2068
+ ownerDialBarrier ,
2069
+ regularDialBarrier ,
2070
+ dialTimeout ,
2071
+ expectedNotifications ,
2072
+ )
2146
2073
2147
2074
th := harness .NewTestHarness (timeoutStrategy .wrapStrategy (harness.ConcurrentExecutionStrategy {}),cleanupStrategy .toStrategy ())
2148
2075
@@ -2446,6 +2373,101 @@ func parseTargetRange(name, targets string) (start, end int, err error) {
2446
2373
return start ,end ,nil
2447
2374
}
2448
2375
2376
+ // triggerUserNotifications waits for all test users to connect,
2377
+ // then creates and deletes a test user to trigger notification events for testing.
2378
+ func triggerUserNotifications (
2379
+ ctx context.Context ,
2380
+ logger slog.Logger ,
2381
+ client * codersdk.Client ,
2382
+ orgID uuid.UUID ,
2383
+ ownerDialBarrier * sync.WaitGroup ,
2384
+ regularDialBarrier * sync.WaitGroup ,
2385
+ dialTimeout time.Duration ,
2386
+ expectedNotifications map [uuid.UUID ]chan time.Time ,
2387
+ ) {
2388
+ logger .Info (ctx ,"waiting for owner users to connect" )
2389
+
2390
+ // Wait for owner users to connect
2391
+ ownerWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
2392
+ defer cancel ()
2393
+
2394
+ ownerDone := make (chan struct {})
2395
+ go func () {
2396
+ ownerDialBarrier .Wait ()
2397
+ close (ownerDone )
2398
+ }()
2399
+
2400
+ select {
2401
+ case <- ownerDone :
2402
+ logger .Info (ctx ,"all owner users connected" )
2403
+ case <- ownerWaitCtx .Done ():
2404
+ if ownerWaitCtx .Err ()== context .DeadlineExceeded {
2405
+ logger .Error (ctx ,"timeout waiting for owner users to connect" )
2406
+ }else {
2407
+ logger .Info (ctx ,"context canceled while waiting for owner users" )
2408
+ }
2409
+ return
2410
+ }
2411
+
2412
+ // Wait for regular users to connect
2413
+ logger .Info (ctx ,"waiting for regular users to connect" )
2414
+ regularWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
2415
+ defer cancel ()
2416
+
2417
+ regularDone := make (chan struct {})
2418
+ go func () {
2419
+ regularDialBarrier .Wait ()
2420
+ close (regularDone )
2421
+ }()
2422
+
2423
+ select {
2424
+ case <- regularDone :
2425
+ logger .Info (ctx ,"all regular users connected" )
2426
+ case <- regularWaitCtx .Done ():
2427
+ if regularWaitCtx .Err ()== context .DeadlineExceeded {
2428
+ logger .Error (ctx ,"timeout waiting for regular users to connect" )
2429
+ }else {
2430
+ logger .Info (ctx ,"context canceled while waiting for regular users" )
2431
+ }
2432
+ return
2433
+ }
2434
+
2435
+ logger .Info (ctx ,"all users connected, triggering notifications" )
2436
+
2437
+ const (
2438
+ triggerUsername = "scaletest-trigger-user"
2439
+ triggerEmail = "scaletest-trigger@example.com"
2440
+ )
2441
+
2442
+ logger .Info (ctx ,"creating test user to test notifications" ,
2443
+ slog .F ("username" ,triggerUsername ),
2444
+ slog .F ("email" ,triggerEmail ),
2445
+ slog .F ("org_id" ,orgID ))
2446
+
2447
+ createTime := time .Now ()
2448
+ testUser ,err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
2449
+ OrganizationIDs : []uuid.UUID {orgID },
2450
+ Username :triggerUsername ,
2451
+ Email :triggerEmail ,
2452
+ Password :"test-password-123" ,
2453
+ })
2454
+ if err != nil {
2455
+ logger .Error (ctx ,"create test user" ,slog .Error (err ))
2456
+ return
2457
+ }
2458
+ expectedNotifications [notificationsLib .TemplateUserAccountCreated ]<- createTime
2459
+
2460
+ deleteTime := time .Now ()
2461
+ err = client .DeleteUser (ctx ,testUser .ID )
2462
+ if err != nil {
2463
+ logger .Error (ctx ,"delete test user" ,slog .Error (err ))
2464
+ return
2465
+ }
2466
+ expectedNotifications [notificationsLib .TemplateUserAccountDeleted ]<- deleteTime
2467
+ close (expectedNotifications [notificationsLib .TemplateUserAccountCreated ])
2468
+ close (expectedNotifications [notificationsLib .TemplateUserAccountDeleted ])
2469
+ }
2470
+
2449
2471
func createWorkspaceAppConfig (client * codersdk.Client ,appHost ,app string ,workspace codersdk.Workspace ,agent codersdk.WorkspaceAgent ) (workspacetraffic.AppConfig ,error ) {
2450
2472
if app == "" {
2451
2473
return workspacetraffic.AppConfig {},nil