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

Commit0be8e28

Browse files
committed
apply review suggestions
1 parente35743f commit0be8e28

File tree

3 files changed

+43
-50
lines changed

3 files changed

+43
-50
lines changed

‎scaletest/notifications/config.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ type Config struct {
3333
// DialBarrier ensures all runners are connected before notifications are triggered.
3434
DialBarrier*sync.WaitGroup`json:"-"`
3535

36-
//OwnerWatchBarrier is the barrier forowner users. Regular users wait on this to disconnect afterowner users complete.
37-
OwnerWatchBarrier*sync.WaitGroup`json:"-"`
36+
//ReceivingWatchBarrier is the barrier forreceiving users. Regular users wait on this to disconnect afterreceiving users complete.
37+
ReceivingWatchBarrier*sync.WaitGroup`json:"-"`
3838
}
3939

4040
func (cConfig)Validate()error {
@@ -51,8 +51,8 @@ func (c Config) Validate() error {
5151
returnxerrors.New("dial barrier must be set")
5252
}
5353

54-
ifc.OwnerWatchBarrier==nil {
55-
returnxerrors.New("owner_watch_barrier must be set")
54+
ifc.ReceivingWatchBarrier==nil {
55+
returnxerrors.New("receiving_watch_barrier must be set")
5656
}
5757

5858
ifc.NotificationTimeout<=0 {

‎scaletest/notifications/run.go‎

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

60-
reachedOwnerWatchBarrier:=false
60+
reachedReceivingWatchBarrier:=false
6161
deferfunc() {
62-
iflen(r.cfg.ExpectedNotifications)>0&&!reachedOwnerWatchBarrier {
63-
r.cfg.OwnerWatchBarrier.Done()
62+
iflen(r.cfg.ExpectedNotifications)>0&&!reachedReceivingWatchBarrier {
63+
r.cfg.ReceivingWatchBarrier.Done()
6464
}
6565
}()
6666

@@ -113,18 +113,18 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
113113
r.cfg.DialBarrier.Wait()
114114

115115
iflen(r.cfg.ExpectedNotifications)==0 {
116-
logger.Info(ctx,"maintaining websocket connection, waiting forowner users to complete")
116+
logger.Info(ctx,"maintaining websocket connection, waiting forreceiving users to complete")
117117

118-
// Wait forowners to complete
118+
// Wait forreceiving users to complete
119119
done:=make(chanstruct{})
120120
gofunc() {
121-
r.cfg.OwnerWatchBarrier.Wait()
121+
r.cfg.ReceivingWatchBarrier.Wait()
122122
close(done)
123123
}()
124124

125125
select {
126126
case<-done:
127-
logger.Info(ctx,"owner users complete, closing connection")
127+
logger.Info(ctx,"receiving users complete, closing connection")
128128
case<-ctx.Done():
129129
logger.Info(ctx,"context canceled, closing connection")
130130
}
@@ -140,8 +140,8 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
140140
returnxerrors.Errorf("notification watch failed: %w",err)
141141
}
142142

143-
reachedOwnerWatchBarrier=true
144-
r.cfg.OwnerWatchBarrier.Done()
143+
reachedReceivingWatchBarrier=true
144+
r.cfg.ReceivingWatchBarrier.Done()
145145

146146
returnnil
147147
}
@@ -160,16 +160,9 @@ func (r *Runner) Cleanup(ctx context.Context, id string, logs io.Writer) error {
160160
constNotificationDeliveryLatencyMetric="notification_delivery_latency_seconds"
161161

162162
func (r*Runner)GetMetrics()map[string]any {
163-
metrics:=map[string]any{}
164-
165-
fortemplateID,latency:=ranger.notificationLatencies {
166-
iflatency>0 {
167-
metricKey:=fmt.Sprintf("%s_%s",NotificationDeliveryLatencyMetric,templateID.String())
168-
metrics[metricKey]=latency.Seconds()
169-
}
163+
returnmap[string]any{
164+
NotificationDeliveryLatencyMetric:r.notificationLatencies,
170165
}
171-
172-
returnmetrics
173166
}
174167

175168
func (r*Runner)dialNotificationWebsocket(ctx context.Context,client*codersdk.Client,user codersdk.User,logger slog.Logger) (*websocket.Conn,error) {
@@ -207,7 +200,7 @@ func (r *Runner) watchNotifications(ctx context.Context, conn *websocket.Conn, u
207200
slog.F("username",user.Username),
208201
slog.F("expected_count",len(expectedNotifications)))
209202

210-
receivedNotifications:=make(map[uuid.UUID]bool)
203+
receivedNotifications:=make(map[uuid.UUID]struct{})
211204

212205
for {
213206
select {
@@ -230,13 +223,14 @@ func (r *Runner) watchNotifications(ctx context.Context, conn *websocket.Conn, u
230223

231224
templateID:=notif.Notification.TemplateID
232225
iftriggerTimeChan,exists:=expectedNotifications[templateID];exists {
233-
if!receivedNotifications[templateID] {
226+
if_,exists:=receivedNotifications[templateID];!exists {
227+
receiptTime:=time.Now()
234228
select {
235229
casetriggerTime:=<-triggerTimeChan:
236-
latency:=time.Since(triggerTime)
230+
latency:=receiptTime.Sub(triggerTime)
237231
r.notificationLatencies[templateID]=latency
238232
r.cfg.Metrics.RecordLatency(latency,user.Username,templateID.String())
239-
receivedNotifications[templateID]=true
233+
receivedNotifications[templateID]=struct{}{}
240234

241235
logger.Info(ctx,"received expected notification",
242236
slog.F("template_id",templateID),

‎scaletest/notifications/run_test.go‎

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package notifications_test
33
import (
44
"io"
55
"strconv"
6-
"strings"
76
"sync"
87
"testing"
98
"time"
@@ -73,12 +72,12 @@ func TestRun(t *testing.T) {
7372
})
7473
firstUser:=coderdtest.CreateFirstUser(t,client)
7574

76-
constnumOwners=2
75+
constnumReceivingUsers=2
7776
constnumRegularUsers=2
7877
dialBarrier:=new(sync.WaitGroup)
79-
ownerWatchBarrier:=new(sync.WaitGroup)
80-
dialBarrier.Add(numOwners+numRegularUsers)
81-
ownerWatchBarrier.Add(numOwners)
78+
receivingWatchBarrier:=new(sync.WaitGroup)
79+
dialBarrier.Add(numReceivingUsers+numRegularUsers)
80+
receivingWatchBarrier.Add(numReceivingUsers)
8281
metrics:=notifications.NewMetrics(prometheus.NewRegistry())
8382

8483
eg,runCtx:=errgroup.WithContext(ctx)
@@ -88,9 +87,9 @@ func TestRun(t *testing.T) {
8887
notificationsLib.TemplateUserAccountDeleted:make(chan time.Time,1),
8988
}
9089

91-
// Startowner runners who will receive notifications
92-
ownerRunners:=make([]*notifications.Runner,0,numOwners)
93-
fori:=rangenumOwners {
90+
// Startreceiving runners who will receive notifications
91+
receivingRunners:=make([]*notifications.Runner,0,numReceivingUsers)
92+
fori:=rangenumReceivingUsers {
9493
runnerCfg:= notifications.Config{
9594
User: createusers.Config{
9695
OrganizationID:firstUser.OrganizationID,
@@ -100,16 +99,16 @@ func TestRun(t *testing.T) {
10099
DialTimeout:testutil.WaitLong,
101100
Metrics:metrics,
102101
DialBarrier:dialBarrier,
103-
OwnerWatchBarrier:ownerWatchBarrier,
102+
ReceivingWatchBarrier:receivingWatchBarrier,
104103
ExpectedNotifications:expectedNotifications,
105104
}
106105
err:=runnerCfg.Validate()
107106
require.NoError(t,err)
108107

109108
runner:=notifications.NewRunner(client,runnerCfg)
110-
ownerRunners=append(ownerRunners,runner)
109+
receivingRunners=append(receivingRunners,runner)
111110
eg.Go(func()error {
112-
returnrunner.Run(runCtx,"owner-"+strconv.Itoa(i),io.Discard)
111+
returnrunner.Run(runCtx,"receiving-"+strconv.Itoa(i),io.Discard)
113112
})
114113
}
115114

@@ -120,12 +119,12 @@ func TestRun(t *testing.T) {
120119
User: createusers.Config{
121120
OrganizationID:firstUser.OrganizationID,
122121
},
123-
Roles: []string{},
124-
NotificationTimeout:testutil.WaitLong,
125-
DialTimeout:testutil.WaitLong,
126-
Metrics:metrics,
127-
DialBarrier:dialBarrier,
128-
OwnerWatchBarrier:ownerWatchBarrier,
122+
Roles:[]string{},
123+
NotificationTimeout:testutil.WaitLong,
124+
DialTimeout:testutil.WaitLong,
125+
Metrics:metrics,
126+
DialBarrier:dialBarrier,
127+
ReceivingWatchBarrier:receivingWatchBarrier,
129128
}
130129
err:=runnerCfg.Validate()
131130
require.NoError(t,err)
@@ -170,9 +169,9 @@ func TestRun(t *testing.T) {
170169
require.NoError(t,err,"runner execution should complete successfully")
171170

172171
cleanupEg,cleanupCtx:=errgroup.WithContext(ctx)
173-
fori,runner:=rangeownerRunners {
172+
fori,runner:=rangereceivingRunners {
174173
cleanupEg.Go(func()error {
175-
returnrunner.Cleanup(cleanupCtx,"owner-"+strconv.Itoa(i),io.Discard)
174+
returnrunner.Cleanup(cleanupCtx,"receiving-"+strconv.Itoa(i),io.Discard)
176175
})
177176
}
178177
fori,runner:=rangeregularRunners {
@@ -188,15 +187,15 @@ func TestRun(t *testing.T) {
188187
require.Len(t,users.Users,1)
189188
require.Equal(t,firstUser.UserID,users.Users[0].ID)
190189

191-
for_,runner:=rangeownerRunners {
192-
runnerMetrics:=runner.GetMetrics()
190+
for_,runner:=rangereceivingRunners {
191+
runnerMetrics:=runner.GetMetrics()[notifications.NotificationDeliveryLatencyMetric]
193192
foundCreated:=false
194193
foundDeleted:=false
195-
forkey:=rangerunnerMetrics {
196-
ifstrings.Contains(key,notificationsLib.TemplateUserAccountCreated.String()) {
194+
forkey:=rangerunnerMetrics.(map[uuid.UUID]time.Duration) {
195+
ifkey==notificationsLib.TemplateUserAccountCreated {
197196
foundCreated=true
198197
}
199-
ifstrings.Contains(key,notificationsLib.TemplateUserAccountDeleted.String()) {
198+
ifkey==notificationsLib.TemplateUserAccountDeleted {
200199
foundDeleted=true
201200
}
202201
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp