@@ -17,6 +17,7 @@ package executor_test
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "strconv"
20
21
"testing"
21
22
"time"
22
23
@@ -1406,14 +1407,30 @@ func TestStaleTSO(t *testing.T) {
1406
1407
tk .MustExec ("create table t (id int)" )
1407
1408
1408
1409
tk .MustExec ("insert into t values(1)" )
1410
+ ts1 , err := strconv .ParseUint (tk .MustQuery ("select json_extract(@@tidb_last_txn_info, '$.commit_ts')" ).Rows ()[0 ][0 ].(string ), 10 , 64 )
1411
+ require .NoError (t , err )
1412
+
1413
+ // Wait until the physical advances for 1s
1414
+ var currentTS uint64
1415
+ for {
1416
+ tk .MustExec ("begin" )
1417
+ currentTS , err = strconv .ParseUint (tk .MustQuery ("select @@tidb_current_ts" ).Rows ()[0 ][0 ].(string ), 10 , 64 )
1418
+ require .NoError (t , err )
1419
+ tk .MustExec ("rollback" )
1420
+ if oracle .GetTimeFromTS (currentTS ).After (oracle .GetTimeFromTS (ts1 ).Add (time .Second )) {
1421
+ break
1422
+ }
1423
+ time .Sleep (time .Millisecond * 100 )
1424
+ }
1409
1425
1410
1426
asOfExprs := []string {
1411
- "now(3) - interval 1 second" ,
1412
- "current_time() - interval 1 second" ,
1413
- "curtime() - interval 1 second" ,
1427
+ "now(3) - interval 10 second" ,
1428
+ "current_time() - interval 10 second" ,
1429
+ "curtime() - interval 10 second" ,
1414
1430
}
1415
1431
1416
- nextTSO := oracle .GoTimeToTS (time .Now ().Add (2 * time .Second ))
1432
+ nextPhysical := oracle .GetPhysical (oracle .GetTimeFromTS (currentTS ).Add (10 * time .Second ))
1433
+ nextTSO := oracle .ComposeTS (nextPhysical , oracle .ExtractLogical (currentTS ))
1417
1434
require .Nil (t , failpoint .Enable ("github.com/pingcap/tidb/sessiontxn/staleread/mockStaleReadTSO" , fmt .Sprintf ("return(%d)" , nextTSO )))
1418
1435
defer failpoint .Disable ("github.com/pingcap/tidb/sessiontxn/staleread/mockStaleReadTSO" )
1419
1436
for _ , expr := range asOfExprs {
0 commit comments