Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite35743f

Browse files
committed
apply review suggestions
1 parent3db0798 commite35743f

File tree

3 files changed

+36
-41
lines changed

3 files changed

+36
-41
lines changed

‎scaletest/notifications/config.go‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ type Config struct {
1515
// User is the configuration for the user to create.
1616
User createusers.Config`json:"user"`
1717

18-
// IsOwner indicates if this user should be assigned Owner role.
19-
// If true, the user will receive notifications.
20-
IsOwnerbool`json:"is_owner"`
18+
// Roles are the roles to assign to the user.
19+
Roles []string`json:"roles"`
2120

2221
// NotificationTimeout is how long to wait for notifications after triggering.
2322
NotificationTimeout time.Duration`json:"notification_timeout"`
@@ -34,8 +33,8 @@ type Config struct {
3433
// DialBarrier ensures all runners are connected before notifications are triggered.
3534
DialBarrier*sync.WaitGroup`json:"-"`
3635

37-
//OwnerDialBarrier is the barrier for owner users. Regular users wait on this to disconnect after owner users complete.
38-
OwnerDialBarrier*sync.WaitGroup`json:"-"`
36+
//OwnerWatchBarrier is the barrier for owner users. Regular users wait on this to disconnect after owner users complete.
37+
OwnerWatchBarrier*sync.WaitGroup`json:"-"`
3938
}
4039

4140
func (cConfig)Validate()error {
@@ -52,12 +51,8 @@ func (c Config) Validate() error {
5251
returnxerrors.New("dial barrier must be set")
5352
}
5453

55-
if!c.IsOwner&&c.OwnerDialBarrier==nil {
56-
returnxerrors.New("owner_dial_barrier must be set for regular users")
57-
}
58-
59-
ifc.IsOwner&&len(c.ExpectedNotifications)==0 {
60-
returnxerrors.New("expected_notifications must be set for owner users")
54+
ifc.OwnerWatchBarrier==nil {
55+
returnxerrors.New("owner_watch_barrier must be set")
6156
}
6257

6358
ifc.NotificationTimeout<=0 {

‎scaletest/notifications/run.go‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
5757
}
5858
}()
5959

60+
reachedOwnerWatchBarrier:=false
61+
deferfunc() {
62+
iflen(r.cfg.ExpectedNotifications)>0&&!reachedOwnerWatchBarrier {
63+
r.cfg.OwnerWatchBarrier.Done()
64+
}
65+
}()
66+
6067
logs=loadtestutil.NewSyncWriter(logs)
6168
logger:=slog.Make(sloghuman.Sink(logs)).Leveled(slog.LevelDebug)
6269
r.client.SetLogger(logger)
@@ -76,15 +83,15 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
7683

7784
logger.Info(ctx,"runner user created",slog.F("username",newUser.Username),slog.F("user_id",newUser.ID.String()))
7885

79-
ifr.cfg.IsOwner {
80-
logger.Info(ctx,"assigningOwner roleto user")
86+
iflen(r.cfg.Roles)>0 {
87+
logger.Info(ctx,"assigningrolesto user",slog.F("roles",r.cfg.Roles))
8188

8289
_,err:=r.client.UpdateUserRoles(ctx,newUser.ID.String(), codersdk.UpdateRoles{
83-
Roles:[]string{codersdk.RoleOwner},
90+
Roles:r.cfg.Roles,
8491
})
8592
iferr!=nil {
86-
r.cfg.Metrics.AddError(newUser.Username,"assign_owner_role")
87-
returnxerrors.Errorf("assignowner role: %w",err)
93+
r.cfg.Metrics.AddError(newUser.Username,"assign_roles")
94+
returnxerrors.Errorf("assignroles: %w",err)
8895
}
8996
}
9097

@@ -105,13 +112,13 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
105112
r.cfg.DialBarrier.Done()
106113
r.cfg.DialBarrier.Wait()
107114

108-
if!r.cfg.IsOwner {
115+
iflen(r.cfg.ExpectedNotifications)==0 {
109116
logger.Info(ctx,"maintaining websocket connection, waiting for owner users to complete")
110117

111118
// Wait for owners to complete
112119
done:=make(chanstruct{})
113120
gofunc() {
114-
r.cfg.OwnerDialBarrier.Wait()
121+
r.cfg.OwnerWatchBarrier.Wait()
115122
close(done)
116123
}()
117124

@@ -133,6 +140,9 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
133140
returnxerrors.Errorf("notification watch failed: %w",err)
134141
}
135142

143+
reachedOwnerWatchBarrier=true
144+
r.cfg.OwnerWatchBarrier.Done()
145+
136146
returnnil
137147
}
138148

@@ -197,10 +207,7 @@ func (r *Runner) watchNotifications(ctx context.Context, conn *websocket.Conn, u
197207
slog.F("username",user.Username),
198208
slog.F("expected_count",len(expectedNotifications)))
199209

200-
receivedNotifications:=make(map[uuid.UUID]bool,len(expectedNotifications))
201-
fortemplateID:=rangeexpectedNotifications {
202-
receivedNotifications[templateID]=false
203-
}
210+
receivedNotifications:=make(map[uuid.UUID]bool)
204211

205212
for {
206213
select {
@@ -209,14 +216,7 @@ func (r *Runner) watchNotifications(ctx context.Context, conn *websocket.Conn, u
209216
default:
210217
}
211218

212-
allReceived:=true
213-
for_,received:=rangereceivedNotifications {
214-
if!received {
215-
allReceived=false
216-
break
217-
}
218-
}
219-
ifallReceived {
219+
iflen(receivedNotifications)==len(expectedNotifications) {
220220
logger.Info(ctx,"received all expected notifications")
221221
returnnil
222222
}

‎scaletest/notifications/run_test.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ func TestRun(t *testing.T) {
7575

7676
constnumOwners=2
7777
constnumRegularUsers=2
78-
ownerBarrier:=new(sync.WaitGroup)
79-
regularBarrier:=new(sync.WaitGroup)
80-
ownerBarrier.Add(numOwners)
81-
regularBarrier.Add(numRegularUsers)
78+
dialBarrier:=new(sync.WaitGroup)
79+
ownerWatchBarrier:=new(sync.WaitGroup)
80+
dialBarrier.Add(numOwners+numRegularUsers)
81+
ownerWatchBarrier.Add(numOwners)
8282
metrics:=notifications.NewMetrics(prometheus.NewRegistry())
8383

8484
eg,runCtx:=errgroup.WithContext(ctx)
@@ -95,11 +95,12 @@ func TestRun(t *testing.T) {
9595
User: createusers.Config{
9696
OrganizationID:firstUser.OrganizationID,
9797
},
98-
IsOwner:true,
98+
Roles: []string{codersdk.RoleOwner},
9999
NotificationTimeout:testutil.WaitLong,
100100
DialTimeout:testutil.WaitLong,
101101
Metrics:metrics,
102-
DialBarrier:ownerBarrier,
102+
DialBarrier:dialBarrier,
103+
OwnerWatchBarrier:ownerWatchBarrier,
103104
ExpectedNotifications:expectedNotifications,
104105
}
105106
err:=runnerCfg.Validate()
@@ -119,12 +120,12 @@ func TestRun(t *testing.T) {
119120
User: createusers.Config{
120121
OrganizationID:firstUser.OrganizationID,
121122
},
122-
IsOwner:false,
123+
Roles: []string{},
123124
NotificationTimeout:testutil.WaitLong,
124125
DialTimeout:testutil.WaitLong,
125126
Metrics:metrics,
126-
DialBarrier:regularBarrier,
127-
OwnerDialBarrier:ownerBarrier,
127+
DialBarrier:dialBarrier,
128+
OwnerWatchBarrier:ownerWatchBarrier,
128129
}
129130
err:=runnerCfg.Validate()
130131
require.NoError(t,err)
@@ -139,8 +140,7 @@ func TestRun(t *testing.T) {
139140
// Trigger notifications by creating and deleting a user
140141
eg.Go(func()error {
141142
// Wait for all runners to connect
142-
ownerBarrier.Wait()
143-
regularBarrier.Wait()
143+
dialBarrier.Wait()
144144

145145
createTime:=time.Now()
146146
newUser,err:=client.CreateUserWithOrgs(runCtx, codersdk.CreateUserRequestWithOrgs{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp