Skip to content

Commit

Permalink
br: fix flaky test TestStoreRemoved (#52834) (#54572)
Browse files Browse the repository at this point in the history
close #52791, close #52792
  • Loading branch information
ti-chi-bot authored Jul 11, 2024
1 parent 1ad607b commit b32b212
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions br/pkg/streamhelper/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"sync"
"testing"
"time"

"github.com/pingcap/tidb/br/pkg/streamhelper"
"github.com/pingcap/tidb/br/pkg/streamhelper/spans"
Expand All @@ -32,6 +33,16 @@ func installSubscribeSupportForRandomN(c *fakeCluster, n int) {
}
}

func waitPendingEvents(t *testing.T, sub *streamhelper.FlushSubscriber) {
last := len(sub.Events())
time.Sleep(100 * time.Microsecond)
require.Eventually(t, func() bool {
noProg := len(sub.Events()) == last
last = len(sub.Events())
return noProg
}, 3*time.Second, 100*time.Millisecond)
}

func TestSubBasic(t *testing.T) {
req := require.New(t)
ctx := context.Background()
Expand All @@ -47,6 +58,7 @@ func TestSubBasic(t *testing.T) {
}
sub.HandleErrors(ctx)
req.NoError(sub.PendingErrors())
waitPendingEvents(t, sub)
sub.Drop()
s := spans.Sorted(spans.NewFullWith(spans.Full(), 1))
for k := range sub.Events() {
Expand Down Expand Up @@ -81,6 +93,7 @@ func TestNormalError(t *testing.T) {
cp = c.advanceCheckpoints()
c.flushAll()
}
waitPendingEvents(t, sub)
sub.Drop()
s := spans.Sorted(spans.NewFullWith(spans.Full(), 1))
for k := range sub.Events() {
Expand Down Expand Up @@ -155,6 +168,7 @@ func TestStoreRemoved(t *testing.T) {
sub.HandleErrors(ctx)
req.NoError(sub.PendingErrors())

waitPendingEvents(t, sub)
sub.Drop()
s := spans.Sorted(spans.NewFullWith(spans.Full(), 1))
for k := range sub.Events() {
Expand Down Expand Up @@ -188,6 +202,8 @@ func TestSomeOfStoreUnsupported(t *testing.T) {
}
s := spans.Sorted(spans.NewFullWith(spans.Full(), 1))
m := new(sync.Mutex)

waitPendingEvents(t, sub)
sub.Drop()
for k := range sub.Events() {
s.Merge(k)
Expand Down

0 comments on commit b32b212

Please sign in to comment.