@@ -3,7 +3,6 @@ package notifications_test
3
3
import (
4
4
"io"
5
5
"strconv"
6
- "strings"
7
6
"sync"
8
7
"testing"
9
8
"time"
@@ -73,12 +72,12 @@ func TestRun(t *testing.T) {
73
72
})
74
73
firstUser := coderdtest .CreateFirstUser (t ,client )
75
74
76
- const numOwners = 2
75
+ const numReceivingUsers = 2
77
76
const numRegularUsers = 2
78
77
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 )
82
81
metrics := notifications .NewMetrics (prometheus .NewRegistry ())
83
82
84
83
eg ,runCtx := errgroup .WithContext (ctx )
@@ -88,9 +87,9 @@ func TestRun(t *testing.T) {
88
87
notificationsLib .TemplateUserAccountDeleted :make (chan time.Time ,1 ),
89
88
}
90
89
91
- // Startowner runners who will receive notifications
92
- ownerRunners := make ([]* notifications.Runner ,0 ,numOwners )
93
- for i := range numOwners {
90
+ // Startreceiving runners who will receive notifications
91
+ receivingRunners := make ([]* notifications.Runner ,0 ,numReceivingUsers )
92
+ for i := range numReceivingUsers {
94
93
runnerCfg := notifications.Config {
95
94
User : createusers.Config {
96
95
OrganizationID :firstUser .OrganizationID ,
@@ -100,16 +99,16 @@ func TestRun(t *testing.T) {
100
99
DialTimeout :testutil .WaitLong ,
101
100
Metrics :metrics ,
102
101
DialBarrier :dialBarrier ,
103
- OwnerWatchBarrier : ownerWatchBarrier ,
102
+ ReceivingWatchBarrier : receivingWatchBarrier ,
104
103
ExpectedNotifications :expectedNotifications ,
105
104
}
106
105
err := runnerCfg .Validate ()
107
106
require .NoError (t ,err )
108
107
109
108
runner := notifications .NewRunner (client ,runnerCfg )
110
- ownerRunners = append (ownerRunners ,runner )
109
+ receivingRunners = append (receivingRunners ,runner )
111
110
eg .Go (func ()error {
112
- return runner .Run (runCtx ,"owner -" + strconv .Itoa (i ),io .Discard )
111
+ return runner .Run (runCtx ,"receiving -" + strconv .Itoa (i ),io .Discard )
113
112
})
114
113
}
115
114
@@ -120,12 +119,12 @@ func TestRun(t *testing.T) {
120
119
User : createusers.Config {
121
120
OrganizationID :firstUser .OrganizationID ,
122
121
},
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 ,
129
128
}
130
129
err := runnerCfg .Validate ()
131
130
require .NoError (t ,err )
@@ -170,9 +169,9 @@ func TestRun(t *testing.T) {
170
169
require .NoError (t ,err ,"runner execution should complete successfully" )
171
170
172
171
cleanupEg ,cleanupCtx := errgroup .WithContext (ctx )
173
- for i ,runner := range ownerRunners {
172
+ for i ,runner := range receivingRunners {
174
173
cleanupEg .Go (func ()error {
175
- return runner .Cleanup (cleanupCtx ,"owner -" + strconv .Itoa (i ),io .Discard )
174
+ return runner .Cleanup (cleanupCtx ,"receiving -" + strconv .Itoa (i ),io .Discard )
176
175
})
177
176
}
178
177
for i ,runner := range regularRunners {
@@ -188,15 +187,15 @@ func TestRun(t *testing.T) {
188
187
require .Len (t ,users .Users ,1 )
189
188
require .Equal (t ,firstUser .UserID ,users .Users [0 ].ID )
190
189
191
- for _ ,runner := range ownerRunners {
192
- runnerMetrics := runner .GetMetrics ()
190
+ for _ ,runner := range receivingRunners {
191
+ runnerMetrics := runner .GetMetrics ()[ notifications . NotificationDeliveryLatencyMetric ]
193
192
foundCreated := false
194
193
foundDeleted := false
195
- for key := range runnerMetrics {
196
- if strings . Contains ( key , notificationsLib .TemplateUserAccountCreated . String ()) {
194
+ for key := range runnerMetrics .( map [uuid. UUID ]time. Duration ) {
195
+ if key == notificationsLib .TemplateUserAccountCreated {
197
196
foundCreated = true
198
197
}
199
- if strings . Contains ( key , notificationsLib .TemplateUserAccountDeleted . String ()) {
198
+ if key == notificationsLib .TemplateUserAccountDeleted {
200
199
foundDeleted = true
201
200
}
202
201
}