Skip to content

Commit ae9f063

Browse files
committed
fi new params
1 parent ebfb7da commit ae9f063

File tree

6 files changed

+50
-32
lines changed

6 files changed

+50
-32
lines changed

maintnotifications/e2e/notiftracker_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,37 @@ func (tnh *TrackingNotificationsHook) Clear() {
8181
tnh.migratedCount.Store(0)
8282
tnh.failingOverCount.Store(0)
8383
}
84+
// wait for notification in prehook
85+
func (tnh *TrackingNotificationsHook) FindOrWaitForNotification(notificationType string, timeout time.Duration) (notification []interface{}, found bool) {
86+
if notification, found := tnh.FindNotification(notificationType); found {
87+
return notification, true
88+
}
89+
90+
// wait for notification
91+
timeoutCh := time.After(timeout)
92+
ticker := time.NewTicker(100 * time.Millisecond)
93+
for {
94+
select {
95+
case <-timeoutCh:
96+
return nil, false
97+
case <-ticker.C:
98+
if notification, found := tnh.FindNotification(notificationType); found {
99+
return notification, true
100+
}
101+
}
102+
}
103+
}
104+
105+
func (tnh *TrackingNotificationsHook) FindNotification(notificationType string) (notification []interface{}, found bool) {
106+
tnh.mutex.RLock()
107+
defer tnh.mutex.RUnlock()
108+
for _, event := range tnh.diagnosticsLog {
109+
if event.Type == notificationType {
110+
return event.Details["notification"].([]interface{}), true
111+
}
112+
}
113+
return nil, false
114+
}
84115

85116
// PreHook captures timeout-related events before processing
86117
func (tnh *TrackingNotificationsHook) PreHook(_ context.Context, notificationCtx push.NotificationHandlerContext, notificationType string, notification []interface{}) ([]interface{}, bool) {

maintnotifications/e2e/scenario_endpoint_types_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
173173
failoverResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
174174
Type: "failover",
175175
Parameters: map[string]interface{}{
176-
"cluster_index": "0",
177-
"bdb_id": endpointConfig.BdbID,
176+
"bdb_id": endpointConfig.BdbID,
178177
},
179178
})
180179
if err != nil {
@@ -223,7 +222,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
223222
migrateResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
224223
Type: "migrate",
225224
Parameters: map[string]interface{}{
226-
"cluster_index": "0",
225+
"bdb_id": endpointConfig.BdbID,
227226
},
228227
})
229228
if err != nil {
@@ -266,8 +265,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
266265
bindResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
267266
Type: "bind",
268267
Parameters: map[string]interface{}{
269-
"cluster_index": "0",
270-
"bdb_id": endpointConfig.BdbID,
268+
"bdb_id": endpointConfig.BdbID,
271269
},
272270
})
273271
if err != nil {

maintnotifications/e2e/scenario_push_notifications_test.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ func TestPushNotifications(t *testing.T) {
147147
failoverResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
148148
Type: "failover",
149149
Parameters: map[string]interface{}{
150-
"cluster_index": "0",
151-
"bdb_id": endpointConfig.BdbID,
150+
"bdb_id": endpointConfig.BdbID,
152151
},
153152
})
154153
if err != nil {
@@ -199,7 +198,7 @@ func TestPushNotifications(t *testing.T) {
199198
migrateResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
200199
Type: "migrate",
201200
Parameters: map[string]interface{}{
202-
"cluster_index": "0",
201+
"bdb_id": endpointConfig.BdbID,
203202
},
204203
})
205204
if err != nil {
@@ -251,8 +250,7 @@ func TestPushNotifications(t *testing.T) {
251250
bindResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
252251
Type: "bind",
253252
Parameters: map[string]interface{}{
254-
"cluster_index": "0",
255-
"bdb_id": endpointConfig.BdbID,
253+
"bdb_id": endpointConfig.BdbID,
256254
},
257255
})
258256
if err != nil {
@@ -297,7 +295,7 @@ func TestPushNotifications(t *testing.T) {
297295
}
298296
}()
299297

300-
p("Waiting for MOVING notification on second client")
298+
p("Waiting for MOVING notification on first client")
301299
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
302300
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING")
303301
}, 3*time.Minute)
@@ -314,6 +312,7 @@ func TestPushNotifications(t *testing.T) {
314312
// wait for moving on second client
315313
// we know the maxconn is 15, assuming 16/17 was used to init the second client, so connID 18 should be from the second client
316314
// also validate big enough relaxed timeout
315+
p("Waiting for MOVING notification on second client")
317316
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
318317
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING") && connID(s, 18)
319318
}, 3*time.Minute)
@@ -372,27 +371,21 @@ func TestPushNotifications(t *testing.T) {
372371
p("Third client created")
373372
go commandsRunner3.FireCommandsUntilStop(ctx)
374373
// wait for moving on third client
375-
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
376-
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING") && connID(s, 19)
377-
}, 3*time.Minute)
374+
movingNotification, found := tracker.FindOrWaitForNotification("MOVING", 3*time.Minute)
378375
if !found {
379376
p("[NOTICE] MOVING notification was not received within 3 minutes ON A THIRD CLIENT")
380377
} else {
381-
data := logs2.ExtractDataFromLogMessage(match)
382378
p("MOVING notification received on third client. %v", data)
383-
mNotif := data["notification"].(string)
384-
// format MOVING <seqID> <timeS> endpoint
385-
mNotifParts := strings.Split(mNotif, " ")
386-
if len(mNotifParts) != 4 {
387-
ef("Invalid MOVING notification format: %s", mNotif)
379+
if len(movingNotification) != 4 {
380+
p("[NOTICE] Invalid MOVING notification format: %s", mNotif)
388381
}
389-
mNotifTimeS, err := strconv.Atoi(mNotifParts[2])
382+
mNotifTimeS, err := strconv.Atoi(movingNotification[2].(string))
390383
if err != nil {
391-
ef("Invalid timeS in MOVING notification: %s", mNotif)
384+
p("[NOTICE] Invalid timeS in MOVING notification: %s", movingNotification)
392385
}
393386
// expect timeS to be less than 15
394387
if mNotifTimeS < 15 {
395-
ef("Expected timeS < 15, got %d", mNotifTimeS)
388+
p("[NOTICE] Expected timeS < 15, got %d", mNotifTimeS)
396389
}
397390
}
398391
commandsRunner3.Stop()

maintnotifications/e2e/scenario_stress_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,14 @@ func TestStressPushNotifications(t *testing.T) {
188188
resp, err = faultInjector.TriggerAction(ctx, ActionRequest{
189189
Type: "failover",
190190
Parameters: map[string]interface{}{
191-
"cluster_index": "0",
192-
"bdb_id": endpointConfig.BdbID,
191+
"bdb_id": endpointConfig.BdbID,
193192
},
194193
})
195194
case "migrate":
196195
resp, err = faultInjector.TriggerAction(ctx, ActionRequest{
197196
Type: "migrate",
198197
Parameters: map[string]interface{}{
199-
"cluster_index": "0",
198+
"bdb_id": endpointConfig.BdbID,
200199
},
201200
})
202201
}

maintnotifications/e2e/scenario_timeout_configs_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
195195
failoverResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
196196
Type: "failover",
197197
Parameters: map[string]interface{}{
198-
"cluster_index": "0",
199198
"bdb_id": endpointConfig.BdbID,
200199
},
201200
})
@@ -244,7 +243,7 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
244243
migrateResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
245244
Type: "migrate",
246245
Parameters: map[string]interface{}{
247-
"cluster_index": "0",
246+
"bdb_id": endpointConfig.BdbID,
248247
},
249248
})
250249
if err != nil {
@@ -275,7 +274,6 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
275274
bindResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
276275
Type: "bind",
277276
Parameters: map[string]interface{}{
278-
"cluster_index": "0",
279277
"bdb_id": endpointConfig.BdbID,
280278
},
281279
})

maintnotifications/e2e/scenario_tls_configs_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ func ТestTLSConfigurationsPushNotifications(t *testing.T) {
197197
failoverResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
198198
Type: "failover",
199199
Parameters: map[string]interface{}{
200-
"cluster_index": "0",
201-
"bdb_id": endpointConfig.BdbID,
200+
"bdb_id": endpointConfig.BdbID,
202201
},
203202
})
204203
if err != nil {
@@ -242,7 +241,7 @@ func ТestTLSConfigurationsPushNotifications(t *testing.T) {
242241
migrateResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
243242
Type: "migrate",
244243
Parameters: map[string]interface{}{
245-
"cluster_index": "0",
244+
"bdb_id": endpointConfig.BdbID,
246245
},
247246
})
248247
if err != nil {

0 commit comments

Comments
 (0)