Skip to content

Commit 7b9984f

Browse files
committed
Fix wait group race in test
1 parent 8d15a23 commit 7b9984f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

rest/blip_legacy_revid_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,14 @@ func TestChangesResponseLegacyRev(t *testing.T) {
552552
// wait for pending change to avoid flakes where changes feed didn't pick up this change
553553
rt.WaitForPendingChanges()
554554
receivedChangesRequestWg := sync.WaitGroup{}
555+
// changes will be called:
556+
// 1. doc1 changes
557+
// 2. empty changes to indicate feed is complete
558+
receivedChangesRequestWg.Add(2)
559+
555560
revsFinishedWg := sync.WaitGroup{}
561+
// expect 1 rev message for doc1
562+
revsFinishedWg.Add(1)
556563

557564
bt.blipContext.HandlerForProfile["rev"] = func(request *blip.Message) {
558565
defer revsFinishedWg.Done()
@@ -571,7 +578,7 @@ func TestChangesResponseLegacyRev(t *testing.T) {
571578
}
572579

573580
bt.blipContext.HandlerForProfile["changes"] = func(request *blip.Message) {
574-
581+
defer receivedChangesRequestWg.Done()
575582
log.Printf("got changes message: %+v", request)
576583
body, err := request.Body()
577584
log.Printf("changes body: %v, err: %v", string(body), err)
@@ -602,19 +609,13 @@ func TestChangesResponseLegacyRev(t *testing.T) {
602609
require.NoError(t, err)
603610
response.SetBody(emptyResponseValBytes)
604611
}
605-
receivedChangesRequestWg.Done()
606612
}
607613

608614
subChangesRequest := bt.newRequest()
609615
subChangesRequest.SetProfile("subChanges")
610616
subChangesRequest.Properties["continuous"] = "false"
611617
sent := bt.sender.Send(subChangesRequest)
612618
assert.True(t, sent)
613-
// changes will be called again with empty changes so hence the wait group of 2
614-
receivedChangesRequestWg.Add(2)
615-
616-
// expect 1 rev message
617-
revsFinishedWg.Add(1)
618619

619620
subChangesResponse := subChangesRequest.Response()
620621
assert.Equal(t, subChangesRequest.SerialNumber(), subChangesResponse.SerialNumber())

0 commit comments

Comments
 (0)