Fix flaky tests about notifying changes

This commit is contained in:
Michal Horejsek
2021-01-14 09:31:36 +01:00
parent 0b39b2adf6
commit 5d246d449c
2 changed files with 23 additions and 3 deletions

View File

@ -107,12 +107,16 @@ func (mocks *mocksForStore) newStoreNoEvents(combinedMode bool, msgs ...*pmapi.M
mocks.client.EXPECT().CountMessages("")
// Call to get latest event ID and then to process first event.
eventAfterSyncRequested := make(chan struct{})
mocks.client.EXPECT().GetEvent("").Return(&pmapi.Event{
EventID: "firstEventID",
}, nil)
mocks.client.EXPECT().GetEvent("firstEventID").Return(&pmapi.Event{
EventID: "latestEventID",
}, nil)
mocks.client.EXPECT().GetEvent("firstEventID").DoAndReturn(func(_ string) (*pmapi.Event, error) {
close(eventAfterSyncRequested)
return &pmapi.Event{
EventID: "latestEventID",
}, nil
})
mocks.client.EXPECT().ListMessages(gomock.Any()).Return(msgs, len(msgs), nil).AnyTimes()
for _, msg := range msgs {
@ -131,6 +135,14 @@ func (mocks *mocksForStore) newStoreNoEvents(combinedMode bool, msgs ...*pmapi.M
require.NoError(mocks.tb, err)
// We want to wait until first sync has finished.
// Checking that event after sync was reuested is not the best way to
// do the check, because sync could take more time, but sync is going
// in background and if there is no message to wait for, we don't have
// anything better.
select {
case <-eventAfterSyncRequested:
case <-time.After(5 * time.Second):
}
require.Eventually(mocks.tb, func() bool {
for _, msg := range msgs {
_, err := mocks.store.getMessageFromDB(msg.ID)