Fix flaky TestSecondaryListInPrimaryLock (#318)

This commit is contained in:
Yilin Chen 2021-09-29 13:45:23 +08:00 committed by GitHub
parent 4f806a5442
commit ee5063fec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 11 deletions

View File

@ -39,6 +39,7 @@ import (
"context" "context"
"sort" "sort"
"testing" "testing"
"time"
"github.com/pingcap/errors" "github.com/pingcap/errors"
"github.com/pingcap/failpoint" "github.com/pingcap/failpoint"
@ -179,16 +180,20 @@ func (s *testAsyncCommitFailSuite) TestSecondaryListInPrimaryLock() {
} }
// Ensure the region has been split // Ensure the region has been split
bo := tikv.NewBackofferWithVars(context.Background(), 5000, nil) s.Eventually(func() bool {
loc, err := s.store.GetRegionCache().LocateKey(bo, []byte("i")) checkRegionBound := func(key, startKey, endKey []byte) bool {
s.Nil(err) bo := tikv.NewBackofferWithVars(context.Background(), 5000, nil)
s.Equal(loc.StartKey, []byte("h")) loc, err := s.store.GetRegionCache().LocateKey(bo, key)
s.Equal(loc.EndKey, []byte("o")) s.Nil(err)
if bytes.Equal(loc.StartKey, startKey) && bytes.Equal(loc.EndKey, endKey) {
loc, err = s.store.GetRegionCache().LocateKey(bo, []byte("p")) return true
s.Nil(err) }
s.Equal(loc.StartKey, []byte("o")) s.store.GetRegionCache().InvalidateCachedRegion(loc.Region)
s.Equal(loc.EndKey, []byte("u")) return false
}
return checkRegionBound([]byte("i"), []byte("h"), []byte("o")) &&
checkRegionBound([]byte("p"), []byte("o"), []byte("u"))
}, time.Second, 10*time.Millisecond, "region is not split successfully")
var sessionID uint64 = 0 var sessionID uint64 = 0
test := func(keys []string, values []string) { test := func(keys []string, values []string) {
@ -202,7 +207,7 @@ func (s *testAsyncCommitFailSuite) TestSecondaryListInPrimaryLock() {
s.Nil(failpoint.Enable("tikvclient/asyncCommitDoNothing", "return")) s.Nil(failpoint.Enable("tikvclient/asyncCommitDoNothing", "return"))
err = txn.Commit(ctx) err := txn.Commit(ctx)
s.Nil(err) s.Nil(err)
primary := txn.GetCommitter().GetPrimaryKey() primary := txn.GetCommitter().GetPrimaryKey()