Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions br/pkg/streamhelper/advancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,19 @@ func TestBlocked(t *testing.T) {
ctx := context.Background()
req := require.New(t)
c.splitAndScatter("0012", "0034", "0048")
blockReq := make(chan struct{})
defer close(blockReq)
firstBlocked := make(chan struct{}, 1)
firstBlockedOnce := sync.Once{}
marked := false
for _, s := range c.storeList() {
s.SetGetRegionCheckpointHook(func(glftrr *logbackup.GetLastFlushTSOfRegionRequest) error {
firstBlockedOnce.Do(func() {
firstBlocked <- struct{}{}
})
// blocking the thread.
// this may happen when TiKV goes down or too busy.
<-(chan struct{})(nil)
<-blockReq
return nil
})
marked = true
Expand All @@ -324,14 +331,21 @@ func TestBlocked(t *testing.T) {
adv := streamhelper.NewCheckpointAdvancer(env)
adv.StartTaskListener(ctx)
adv.UpdateConfigWith(func(c *config.CommandConfig) {
// ... So the tick timeout would be 100ms
c.TickDuration = 10 * time.Millisecond
// keep enough headroom so the blocked rpc request is observed before timeout.
c.TickDuration = 100 * time.Millisecond
})
errCh := make(chan error, 1)
go func() {
errCh <- adv.OnTick(ctx)
}()
shouldFinishInTime(t, 5*time.Second, "wait until blocked request observed", func() {
<-firstBlocked
})
var err error
shouldFinishInTime(t, time.Second, "ticking", func() {
err = adv.OnTick(ctx)
shouldFinishInTime(t, 5*time.Second, "ticking", func() {
err = <-errCh
})
req.ErrorIs(errors.Cause(err), context.DeadlineExceeded)
req.ErrorIs(err, context.DeadlineExceeded)
}

func TestResolveLock(t *testing.T) {
Expand Down
Loading