From d6a89c69c210f9e86b45b15bb867b7d02b3e10b8 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sat, 16 Nov 2024 14:32:46 +0530 Subject: [PATCH] Fix flaky test TestScheduledPostStore (#29301) There were couple of errors in the test: 1. UpdatedScheduledPost will automatically set the ProcessedAt to now internally inside toUpdateMap. So setting the value from outside has no effect. 2. The bug was that if it took more than a milisecond to capture the time, and then do the internal call, then the Get call will have a higher value and therefore fail. Since UpdatedScheduledPost doesn't return an updated post, so there is no need to compare the timestamps at all. ```release-note NONE ``` --- server/channels/store/storetest/scheduled_post_store.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/channels/store/storetest/scheduled_post_store.go b/server/channels/store/storetest/scheduled_post_store.go index aa9ca95410..749717eaf6 100644 --- a/server/channels/store/storetest/scheduled_post_store.go +++ b/server/channels/store/storetest/scheduled_post_store.go @@ -349,8 +349,7 @@ func testUpdatedScheduledPost(t *testing.T, rctx request.CTX, ss store.Store, s assert.NotEmpty(t, createdScheduledPost.Id) // now we'll update the scheduled post - processedAt := model.GetMillis() - scheduledPost.ProcessedAt = processedAt + now := model.GetMillis() scheduledPost.ErrorCode = model.ScheduledPostErrorUnknownError err = ss.ScheduledPost().UpdatedScheduledPost(scheduledPost) @@ -358,7 +357,7 @@ func testUpdatedScheduledPost(t *testing.T, rctx request.CTX, ss store.Store, s updatedScheduledPost, err := ss.ScheduledPost().Get(scheduledPost.Id) assert.NoError(t, err) - assert.Equal(t, processedAt, updatedScheduledPost.ProcessedAt) + assert.LessOrEqual(t, now, updatedScheduledPost.ProcessedAt) assert.Equal(t, model.ScheduledPostErrorUnknownError, updatedScheduledPost.ErrorCode) }) }