@@ -1825,89 +1825,16 @@ func (r *RootCmd) scaletestNotifications() *serpent.Command {
1825
1825
configs = append (configs ,config )
1826
1826
}
1827
1827
1828
- go func () {
1829
- logger .Info (ctx ,"waiting for owner users to connect" )
1830
-
1831
- // Wait for owner users to connect
1832
- ownerWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
1833
- defer cancel ()
1834
-
1835
- ownerDone := make (chan struct {})
1836
- go func () {
1837
- ownerDialBarrier .Wait ()
1838
- close (ownerDone )
1839
- }()
1840
-
1841
- select {
1842
- case <- ownerDone :
1843
- logger .Info (ctx ,"all owner users connected" )
1844
- case <- ownerWaitCtx .Done ():
1845
- if ownerWaitCtx .Err ()== context .DeadlineExceeded {
1846
- logger .Error (ctx ,"timeout waiting for owner users to connect" )
1847
- }else {
1848
- logger .Info (ctx ,"context canceled while waiting for owner users" )
1849
- }
1850
- return
1851
- }
1852
-
1853
- // Wait for regular users to connect
1854
- logger .Info (ctx ,"waiting for regular users to connect" )
1855
- regularWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
1856
- defer cancel ()
1857
-
1858
- regularDone := make (chan struct {})
1859
- go func () {
1860
- regularDialBarrier .Wait ()
1861
- close (regularDone )
1862
- }()
1863
-
1864
- select {
1865
- case <- regularDone :
1866
- logger .Info (ctx ,"all regular users connected" )
1867
- case <- regularWaitCtx .Done ():
1868
- if regularWaitCtx .Err ()== context .DeadlineExceeded {
1869
- logger .Error (ctx ,"timeout waiting for regular users to connect" )
1870
- }else {
1871
- logger .Info (ctx ,"context canceled while waiting for regular users" )
1872
- }
1873
- return
1874
- }
1875
-
1876
- logger .Info (ctx ,"all users connected, triggering notifications" )
1877
-
1878
- const (
1879
- triggerUsername = "scaletest-trigger-user"
1880
- triggerEmail = "scaletest-trigger@example.com"
1881
- )
1882
-
1883
- logger .Info (ctx ,"creating test user to test notifications" ,
1884
- slog .F ("username" ,triggerUsername ),
1885
- slog .F ("email" ,triggerEmail ),
1886
- slog .F ("org_id" ,me .OrganizationIDs [0 ]))
1887
-
1888
- createTime := time .Now ()
1889
- testUser ,err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
1890
- OrganizationIDs : []uuid.UUID {me .OrganizationIDs [0 ]},
1891
- Username :triggerUsername ,
1892
- Email :triggerEmail ,
1893
- Password :"test-password-123" ,
1894
- })
1895
- if err != nil {
1896
- logger .Error (ctx ,"create test user" ,slog .Error (err ))
1897
- return
1898
- }
1899
- expectedNotifications [notificationsLib .TemplateUserAccountCreated ]<- createTime
1900
-
1901
- deleteTime := time .Now ()
1902
- err = client .DeleteUser (ctx ,testUser .ID )
1903
- if err != nil {
1904
- logger .Error (ctx ,"delete test user" ,slog .Error (err ))
1905
- return
1906
- }
1907
- expectedNotifications [notificationsLib .TemplateUserAccountDeleted ]<- deleteTime
1908
- close (expectedNotifications [notificationsLib .TemplateUserAccountCreated ])
1909
- close (expectedNotifications [notificationsLib .TemplateUserAccountDeleted ])
1910
- }()
1828
+ go triggerUserNotifications (
1829
+ ctx ,
1830
+ logger ,
1831
+ client ,
1832
+ me .OrganizationIDs [0 ],
1833
+ ownerDialBarrier ,
1834
+ regularDialBarrier ,
1835
+ dialTimeout ,
1836
+ expectedNotifications ,
1837
+ )
1911
1838
1912
1839
th := harness .NewTestHarness (timeoutStrategy .wrapStrategy (harness.ConcurrentExecutionStrategy {}),cleanupStrategy .toStrategy ())
1913
1840
@@ -2211,6 +2138,101 @@ func parseTargetRange(name, targets string) (start, end int, err error) {
2211
2138
return start ,end ,nil
2212
2139
}
2213
2140
2141
+ // triggerUserNotifications waits for all test users to connect,
2142
+ // then creates and deletes a test user to trigger notification events for testing.
2143
+ func triggerUserNotifications (
2144
+ ctx context.Context ,
2145
+ logger slog.Logger ,
2146
+ client * codersdk.Client ,
2147
+ orgID uuid.UUID ,
2148
+ ownerDialBarrier * sync.WaitGroup ,
2149
+ regularDialBarrier * sync.WaitGroup ,
2150
+ dialTimeout time.Duration ,
2151
+ expectedNotifications map [uuid.UUID ]chan time.Time ,
2152
+ ) {
2153
+ logger .Info (ctx ,"waiting for owner users to connect" )
2154
+
2155
+ // Wait for owner users to connect
2156
+ ownerWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
2157
+ defer cancel ()
2158
+
2159
+ ownerDone := make (chan struct {})
2160
+ go func () {
2161
+ ownerDialBarrier .Wait ()
2162
+ close (ownerDone )
2163
+ }()
2164
+
2165
+ select {
2166
+ case <- ownerDone :
2167
+ logger .Info (ctx ,"all owner users connected" )
2168
+ case <- ownerWaitCtx .Done ():
2169
+ if ownerWaitCtx .Err ()== context .DeadlineExceeded {
2170
+ logger .Error (ctx ,"timeout waiting for owner users to connect" )
2171
+ }else {
2172
+ logger .Info (ctx ,"context canceled while waiting for owner users" )
2173
+ }
2174
+ return
2175
+ }
2176
+
2177
+ // Wait for regular users to connect
2178
+ logger .Info (ctx ,"waiting for regular users to connect" )
2179
+ regularWaitCtx ,cancel := context .WithTimeout (ctx ,dialTimeout + 30 * time .Second )
2180
+ defer cancel ()
2181
+
2182
+ regularDone := make (chan struct {})
2183
+ go func () {
2184
+ regularDialBarrier .Wait ()
2185
+ close (regularDone )
2186
+ }()
2187
+
2188
+ select {
2189
+ case <- regularDone :
2190
+ logger .Info (ctx ,"all regular users connected" )
2191
+ case <- regularWaitCtx .Done ():
2192
+ if regularWaitCtx .Err ()== context .DeadlineExceeded {
2193
+ logger .Error (ctx ,"timeout waiting for regular users to connect" )
2194
+ }else {
2195
+ logger .Info (ctx ,"context canceled while waiting for regular users" )
2196
+ }
2197
+ return
2198
+ }
2199
+
2200
+ logger .Info (ctx ,"all users connected, triggering notifications" )
2201
+
2202
+ const (
2203
+ triggerUsername = "scaletest-trigger-user"
2204
+ triggerEmail = "scaletest-trigger@example.com"
2205
+ )
2206
+
2207
+ logger .Info (ctx ,"creating test user to test notifications" ,
2208
+ slog .F ("username" ,triggerUsername ),
2209
+ slog .F ("email" ,triggerEmail ),
2210
+ slog .F ("org_id" ,orgID ))
2211
+
2212
+ createTime := time .Now ()
2213
+ testUser ,err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
2214
+ OrganizationIDs : []uuid.UUID {orgID },
2215
+ Username :triggerUsername ,
2216
+ Email :triggerEmail ,
2217
+ Password :"test-password-123" ,
2218
+ })
2219
+ if err != nil {
2220
+ logger .Error (ctx ,"create test user" ,slog .Error (err ))
2221
+ return
2222
+ }
2223
+ expectedNotifications [notificationsLib .TemplateUserAccountCreated ]<- createTime
2224
+
2225
+ deleteTime := time .Now ()
2226
+ err = client .DeleteUser (ctx ,testUser .ID )
2227
+ if err != nil {
2228
+ logger .Error (ctx ,"delete test user" ,slog .Error (err ))
2229
+ return
2230
+ }
2231
+ expectedNotifications [notificationsLib .TemplateUserAccountDeleted ]<- deleteTime
2232
+ close (expectedNotifications [notificationsLib .TemplateUserAccountCreated ])
2233
+ close (expectedNotifications [notificationsLib .TemplateUserAccountDeleted ])
2234
+ }
2235
+
2214
2236
func createWorkspaceAppConfig (client * codersdk.Client ,appHost ,app string ,workspace codersdk.Workspace ,agent codersdk.WorkspaceAgent ) (workspacetraffic.AppConfig ,error ) {
2215
2237
if app == "" {
2216
2238
return workspacetraffic.AppConfig {},nil