@@ -23,6 +23,7 @@ import (
23
23
24
24
sqlmock "github.com/DATA-DOG/go-sqlmock"
25
25
"github.com/pingcap/tidb/pkg/parser"
26
+ "github.com/pingcap/tidb/pkg/testkit/testfailpoint"
26
27
"github.com/pingcap/tiflow/sync_diff_inspector/chunk"
27
28
"github.com/pingcap/tiflow/sync_diff_inspector/source/common"
28
29
"github.com/pingcap/tiflow/sync_diff_inspector/utils"
@@ -146,7 +147,7 @@ func TestSplitRangeByRandom(t *testing.T) {
146
147
147
148
splitCols , err := GetSplitFields (tableInfo , nil )
148
149
require .NoError (t , err )
149
- createFakeResultForRandomSplit (mock , 0 , testCase .randomValues )
150
+ createFakeResultForRandomSplit (t , mock , 0 , testCase .randomValues )
150
151
chunks , err := splitRangeByRandom (context .Background (), db , testCase .originChunk , testCase .splitCount , "test" , "test" , splitCols , "" , "" )
151
152
require .NoError (t , err )
152
153
for j , chunk := range chunks {
@@ -335,7 +336,7 @@ func TestRandomSpliter(t *testing.T) {
335
336
ChunkSize : 5 ,
336
337
}
337
338
338
- createFakeResultForRandomSplit (mock , testCase .count , testCase .randomValues )
339
+ createFakeResultForRandomSplit (t , mock , testCase .count , testCase .randomValues )
339
340
340
341
iter , err := NewRandomIterator (ctx , "" , tableDiff , db )
341
342
require .NoError (t , err )
@@ -368,7 +369,7 @@ func TestRandomSpliter(t *testing.T) {
368
369
ChunkSize : 5 ,
369
370
}
370
371
371
- createFakeResultForRandomSplit (mock , testCases [0 ].count , testCases [0 ].randomValues )
372
+ createFakeResultForRandomSplit (t , mock , testCases [0 ].count , testCases [0 ].randomValues )
372
373
373
374
iter , err := NewRandomIterator (ctx , "" , tableDiff , db )
374
375
require .NoError (t , err )
@@ -386,7 +387,7 @@ func TestRandomSpliter(t *testing.T) {
386
387
ChunkRange : chunk ,
387
388
}
388
389
389
- createFakeResultForRandomSplit (mock , testCases [0 ].count , testCases [0 ].randomValues )
390
+ createFakeResultForRandomSplit (t , mock , testCases [0 ].count , testCases [0 ].randomValues )
390
391
391
392
iter , err = NewRandomIteratorWithCheckpoint (ctx , "" , tableDiff , db , rangeInfo )
392
393
require .NoError (t , err )
@@ -402,8 +403,8 @@ func TestRandomSpliter(t *testing.T) {
402
403
require .Equal (t , chunk .Index .ChunkIndex , chunkID1 .ChunkIndex + 1 )
403
404
}
404
405
405
- func createFakeResultForRandomSplit (mock sqlmock.Sqlmock , count int , randomValues [][]string ) {
406
- createFakeResultForCount (mock , count )
406
+ func createFakeResultForRandomSplit (t * testing. T , mock sqlmock.Sqlmock , count int , randomValues [][]string ) {
407
+ createFakeResultForCount (t , count )
407
408
if randomValues == nil {
408
409
return
409
410
}
@@ -688,7 +689,7 @@ func TestBucketSpliter(t *testing.T) {
688
689
db , mock , err = sqlmock .New ()
689
690
require .NoError (t , err )
690
691
createFakeResultForBucketSplit (mock , nil , nil )
691
- createFakeResultForCount ( mock , 64 )
692
+ testfailpoint . Enable ( t , "github.com/pingcap/tiflow/sync_diff_inspector/splitter/getRowCount" , "return(64)" )
692
693
createFakeResultForRandom (mock , testCases [0 ].aRandomValues [stopJ :], testCases [0 ].bRandomValues [stopJ :])
693
694
iter , err = NewBucketIteratorWithCheckpoint (ctx , "" , tableDiff , db , rangeInfo , utils .NewWorkerPool (1 , "bucketIter" ))
694
695
require .NoError (t , err )
@@ -722,11 +723,13 @@ func createFakeResultForBucketSplit(mock sqlmock.Sqlmock, aRandomValues, bRandom
722
723
createFakeResultForRandom (mock , aRandomValues , bRandomValues )
723
724
}
724
725
725
- func createFakeResultForCount (mock sqlmock. Sqlmock , count int ) {
726
+ func createFakeResultForCount (t * testing. T , count int ) {
726
727
if count > 0 {
727
728
// generate fake result for get the row count of this table
728
- countRows := sqlmock .NewRows ([]string {"cnt" }).AddRow (count )
729
- mock .ExpectQuery ("SELECT COUNT.*" ).WillReturnRows (countRows )
729
+ testfailpoint .Enable (t ,
730
+ "github.com/pingcap/tiflow/sync_diff_inspector/splitter/getRowCount" ,
731
+ fmt .Sprintf ("return(%d)" , count ),
732
+ )
730
733
}
731
734
}
732
735
@@ -910,12 +913,12 @@ func TestChunkSize(t *testing.T) {
910
913
911
914
// test random splitter chunksize
912
915
// chunkNum is only 1, so don't need randomValues
913
- createFakeResultForRandomSplit (mock , 1000 , nil )
916
+ createFakeResultForRandomSplit (t , mock , 1000 , nil )
914
917
randomIter , err := NewRandomIterator (ctx , "" , tableDiff , db )
915
918
require .NoError (t , err )
916
919
require .Equal (t , randomIter .chunkSize , int64 (50000 ))
917
920
918
- createFakeResultForRandomSplit (mock , 1000000000 , [][]string {
921
+ createFakeResultForRandomSplit (t , mock , 1000000000 , [][]string {
919
922
{"1" , "2" , "3" , "4" , "5" },
920
923
{"a" , "b" , "c" , "d" , "e" },
921
924
})
@@ -934,13 +937,12 @@ func TestChunkSize(t *testing.T) {
934
937
ChunkSize : 0 ,
935
938
}
936
939
// no index
937
- createFakeResultForRandomSplit (mock , 1000 , nil )
940
+ createFakeResultForRandomSplit (t , mock , 1000 , nil )
938
941
randomIter , err = NewRandomIterator (ctx , "" , tableDiffNoIndex , db )
939
942
require .NoError (t , err )
940
943
require .Equal (t , randomIter .chunkSize , int64 (1001 ))
941
944
942
945
// test limit splitter chunksize
943
- createFakeResultForCount (mock , 1000 )
944
946
mock .ExpectQuery ("SELECT `a`,.*limit 50000.*" ).WillReturnRows (sqlmock .NewRows ([]string {"a" , "b" }))
945
947
_ , err = NewLimitIterator (ctx , "" , tableDiff , db )
946
948
require .NoError (t , err )
0 commit comments