test(pubsublite): fix flaky TestMsgTrackerWaitSuccess test (#3560)
Return early if there are no messages to wait for. Just check for error, rather than match the error message.
Fixes https://github.com/googleapis/google-cloud-go/issues/3550.
diff --git a/pubsublite/internal/test/msg_tracker.go b/pubsublite/internal/test/msg_tracker.go
index 35a293d..af95956 100644
--- a/pubsublite/internal/test/msg_tracker.go
+++ b/pubsublite/internal/test/msg_tracker.go
@@ -75,6 +75,10 @@
totalCount := len(mt.msgMap)
mt.mu.Unlock()
+ if totalCount == 0 {
+ return nil
+ }
+
select {
case <-time.After(timeout):
mt.mu.Lock()
diff --git a/pubsublite/internal/test/msg_tracker_test.go b/pubsublite/internal/test/msg_tracker_test.go
index 642bfd3..81d0a88 100644
--- a/pubsublite/internal/test/msg_tracker_test.go
+++ b/pubsublite/internal/test/msg_tracker_test.go
@@ -50,7 +50,7 @@
t.Errorf("MsgTracker.Remove(%q) got %v, want %v", msg, got, want)
}
}
- if gotErr, wantMsg := msgTracker.Wait(time.Millisecond), "received 2 of 3 messages"; ErrorHasMsg(gotErr, wantMsg) {
- t.Errorf("MsgTracker.Wait() got err: %v, want msg: %q", gotErr, wantMsg)
+ if gotErr := msgTracker.Wait(time.Millisecond); gotErr == nil {
+ t.Errorf("MsgTracker.Wait() should return error")
}
}