Skip to content

Commit b03254b

Browse files
committed
updates
1 parent 5ab9859 commit b03254b

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

mongo/integration/cmd_monitoring_helpers_test.go

+39-39
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,22 @@ func compareStartedEvents(mt *mtest.T, expectations []*cmdStartedEvt, id0, id1 b
321321
}
322322

323323
var evt *event.CommandStartedEvent
324-
if expected.CommandName != "" {
325-
// skip events not in expectations
326-
for {
327-
evt = mt.GetStartedEvent()
328-
if evt == nil {
329-
return fmt.Errorf("expected CommandStartedEvent %s, got nil", expected.CommandName)
330-
}
331-
if v, ok := expectedCmds[evt.CommandName]; ok && v {
332-
break
333-
}
324+
// skip events not in expectations
325+
for {
326+
evt = mt.GetStartedEvent()
327+
if evt == nil {
328+
return fmt.Errorf("expected CommandStartedEvent %s, got nil", expected.CommandName)
334329
}
335-
336-
if expected.CommandName != evt.CommandName {
337-
return fmt.Errorf("command name mismatch for started event; expected %s, got %s", expected.CommandName, evt.CommandName)
330+
if expected.CommandName != "" {
331+
break
332+
} else if v, ok := expectedCmds[evt.CommandName]; ok && v {
333+
break
338334
}
339335
}
336+
337+
if expected.CommandName != "" && expected.CommandName != evt.CommandName {
338+
return fmt.Errorf("command name mismatch for started event; expected %s, got %s", expected.CommandName, evt.CommandName)
339+
}
340340
if expected.DatabaseName != "" && expected.DatabaseName != evt.DatabaseName {
341341
return fmt.Errorf("database name mismatch; expected %s, got %s", expected.DatabaseName, evt.DatabaseName)
342342
}
@@ -460,23 +460,23 @@ func compareSucceededEvents(mt *mtest.T, expectations []*cmdSucceededEvt) error
460460
}
461461

462462
var evt *event.CommandSucceededEvent
463-
if expected.CommandName != "" {
464-
// skip events not in expectations
465-
for expected.CommandName != "" {
466-
evt = mt.GetSucceededEvent()
467-
if evt == nil {
468-
return fmt.Errorf("expected CommandSucceededEvent %s, got nil", expected.CommandName)
469-
}
470-
if v, ok := expectedCmds[evt.CommandName]; ok && v {
471-
break
472-
}
463+
// skip events not in expectations
464+
for {
465+
evt = mt.GetSucceededEvent()
466+
if evt == nil {
467+
return fmt.Errorf("expected CommandSucceededEvent %s, got nil", expected.CommandName)
473468
}
474-
475-
if expected.CommandName != evt.CommandName {
476-
return fmt.Errorf("command name mismatch for succeeded event; expected %s, got %s", expected.CommandName, evt.CommandName)
469+
if expected.CommandName != "" {
470+
break
471+
} else if v, ok := expectedCmds[evt.CommandName]; ok && v {
472+
break
477473
}
478474
}
479475

476+
if expected.CommandName != "" && expected.CommandName != evt.CommandName {
477+
return fmt.Errorf("command name mismatch for succeeded event; expected %s, got %s", expected.CommandName, evt.CommandName)
478+
}
479+
480480
eElems, err := expected.Reply.Elements()
481481
if err != nil {
482482
return fmt.Errorf("error getting expected reply elements: %s", err)
@@ -523,22 +523,22 @@ func compareFailedEvents(mt *mtest.T, expectations []*cmdFailedEvt) error {
523523
}
524524

525525
var evt *event.CommandFailedEvent
526-
if expected.CommandName != "" {
527-
// skip events not in expectations
528-
for expected.CommandName != "" {
529-
evt = mt.GetFailedEvent()
530-
if evt == nil {
531-
return fmt.Errorf("expected CommandFailedEvent %s, got nil", expected.CommandName)
532-
}
533-
if v, ok := expectedCmds[evt.CommandName]; ok && v {
534-
break
535-
}
526+
// skip events not in expectations
527+
for {
528+
evt = mt.GetFailedEvent()
529+
if evt == nil {
530+
return fmt.Errorf("expected CommandFailedEvent %s, got nil", expected.CommandName)
536531
}
537-
538-
if expected.CommandName != evt.CommandName {
539-
return fmt.Errorf("command name mismatch for failed event; expected %s, got %s", expected.CommandName, evt.CommandName)
532+
if expected.CommandName != "" {
533+
break
534+
} else if v, ok := expectedCmds[evt.CommandName]; ok && v {
535+
break
540536
}
541537
}
538+
539+
if expected.CommandName != "" && expected.CommandName != evt.CommandName {
540+
return fmt.Errorf("command name mismatch for failed event; expected %s, got %s", expected.CommandName, evt.CommandName)
541+
}
542542
return nil
543543
}
544544
for idx, expected := range expectations {

0 commit comments

Comments
 (0)