Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivs11 committed Oct 7, 2024
1 parent 3207d6a commit 05a2a21
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions service/matching/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,51 @@ func (t *MatcherTestSuite) TestRejectSyncMatchWhenBacklog() {
func (t *MatcherTestSuite) TestForwardingWhenBacklogIsYoung() {
historyTask := newInternalTaskForSyncMatch(randomTaskInfo().Data, nil)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
intruptC := make(chan struct{})

// poll forwarding attempt happens when there is no backlog
t.client.EXPECT().PollWorkflowTaskQueue(gomock.Any(), gomock.Any(), gomock.Any()).Return(&matchingservice.PollWorkflowTaskQueueResponse{}, errMatchingHostThrottleTest)
go t.childMatcher.Poll(ctx, &pollMetadata{}) //nolint:errcheck
time.Sleep(time.Millisecond)
var wg sync.WaitGroup
wg.Add(1)

// task is not forwarded because there is a poller waiting
youngBacklogTask := newInternalTaskFromBacklog(randomTaskInfoWithAge(time.Second), nil)
t.client.EXPECT().PollWorkflowTaskQueue(gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(arg0 context.Context, arg1 *matchingservice.PollWorkflowTaskQueueRequest, arg2 ...interface{}) {
wg.Done()
},
).Return(&matchingservice.PollWorkflowTaskQueueResponse{}, errMatchingHostThrottleTest)

go func() {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
// poll forwarding attempt happens when there is no backlog
_, err := t.childMatcher.Poll(ctx, &pollMetadata{})
t.Assert().NoError(err)
cancel()
}()
// This ensures that the poll request has been forwarded to the parent partition before the offer is made.
// Without this, there is a chance that the request is matched on the child partition, which will fail the test by
// complaining about a missing PollWorkflowTaskQueue.
wg.Wait()

// to ensure poller is now blocked locally
time.Sleep(2 * time.Millisecond)

Check failure on line 295 in service/matching/matcher_test.go

View workflow job for this annotation

GitHub Actions / lint

use of `time.Sleep` forbidden because "Please use require.Eventually or assert.Eventually instead unless you've no other option" (forbidigo)

// task is not forwarded because there is a local poller waiting
err := t.childMatcher.MustOffer(ctx, historyTask, intruptC)
t.Nil(err)
cancel()

// young task is forwarded
t.client.EXPECT().AddWorkflowTask(gomock.Any(), gomock.Any(), gomock.Any()).Return(&matchingservice.AddWorkflowTaskResponse{}, errMatchingHostThrottleTest)
youngBacklogTask := newInternalTaskFromBacklog(randomTaskInfoWithAge(time.Second), nil)

wg.Add(1)
t.client.EXPECT().AddWorkflowTask(gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(arg0 context.Context, arg1 *matchingservice.AddWorkflowTaskRequest, arg2 ...interface{}) {
// Offer forwarding has occured
wg.Done()
},
).Return(&matchingservice.AddWorkflowTaskResponse{}, errMatchingHostThrottleTest)
ctx, cancel = context.WithTimeout(context.Background(), time.Second)
go t.childMatcher.MustOffer(ctx, youngBacklogTask, intruptC) //nolint:errcheck
wg.Wait()
time.Sleep(time.Millisecond)
cancel()
}
Expand Down

0 comments on commit 05a2a21

Please sign in to comment.