@@ -57,6 +57,13 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
57
57
}
58
58
}()
59
59
60
+ reachedOwnerWatchBarrier := false
61
+ defer func () {
62
+ if len (r .cfg .ExpectedNotifications )> 0 && ! reachedOwnerWatchBarrier {
63
+ r .cfg .OwnerWatchBarrier .Done ()
64
+ }
65
+ }()
66
+
60
67
logs = loadtestutil .NewSyncWriter (logs )
61
68
logger := slog .Make (sloghuman .Sink (logs )).Leveled (slog .LevelDebug )
62
69
r .client .SetLogger (logger )
@@ -76,15 +83,15 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
76
83
77
84
logger .Info (ctx ,"runner user created" ,slog .F ("username" ,newUser .Username ),slog .F ("user_id" ,newUser .ID .String ()))
78
85
79
- if r .cfg .IsOwner {
80
- logger .Info (ctx ,"assigningOwner role to user" )
86
+ if len ( r .cfg .Roles ) > 0 {
87
+ logger .Info (ctx ,"assigningroles to user" , slog . F ( "roles" , r . cfg . Roles ) )
81
88
82
89
_ ,err := r .client .UpdateUserRoles (ctx ,newUser .ID .String (), codersdk.UpdateRoles {
83
- Roles :[] string { codersdk . RoleOwner } ,
90
+ Roles :r . cfg . Roles ,
84
91
})
85
92
if err != nil {
86
- r .cfg .Metrics .AddError (newUser .Username ,"assign_owner_role " )
87
- return xerrors .Errorf ("assignowner role : %w" ,err )
93
+ r .cfg .Metrics .AddError (newUser .Username ,"assign_roles " )
94
+ return xerrors .Errorf ("assignroles : %w" ,err )
88
95
}
89
96
}
90
97
@@ -105,13 +112,13 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
105
112
r .cfg .DialBarrier .Done ()
106
113
r .cfg .DialBarrier .Wait ()
107
114
108
- if ! r .cfg .IsOwner {
115
+ if len ( r .cfg .ExpectedNotifications ) == 0 {
109
116
logger .Info (ctx ,"maintaining websocket connection, waiting for owner users to complete" )
110
117
111
118
// Wait for owners to complete
112
119
done := make (chan struct {})
113
120
go func () {
114
- r .cfg .OwnerDialBarrier .Wait ()
121
+ r .cfg .OwnerWatchBarrier .Wait ()
115
122
close (done )
116
123
}()
117
124
@@ -133,6 +140,9 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
133
140
return xerrors .Errorf ("notification watch failed: %w" ,err )
134
141
}
135
142
143
+ reachedOwnerWatchBarrier = true
144
+ r .cfg .OwnerWatchBarrier .Done ()
145
+
136
146
return nil
137
147
}
138
148
@@ -197,10 +207,7 @@ func (r *Runner) watchNotifications(ctx context.Context, conn *websocket.Conn, u
197
207
slog .F ("username" ,user .Username ),
198
208
slog .F ("expected_count" ,len (expectedNotifications )))
199
209
200
- receivedNotifications := make (map [uuid.UUID ]bool ,len (expectedNotifications ))
201
- for templateID := range expectedNotifications {
202
- receivedNotifications [templateID ]= false
203
- }
210
+ receivedNotifications := make (map [uuid.UUID ]bool )
204
211
205
212
for {
206
213
select {
@@ -209,14 +216,7 @@ func (r *Runner) watchNotifications(ctx context.Context, conn *websocket.Conn, u
209
216
default :
210
217
}
211
218
212
- allReceived := true
213
- for _ ,received := range receivedNotifications {
214
- if ! received {
215
- allReceived = false
216
- break
217
- }
218
- }
219
- if allReceived {
219
+ if len (receivedNotifications )== len (expectedNotifications ) {
220
220
logger .Info (ctx ,"received all expected notifications" )
221
221
return nil
222
222
}