Skip to content
Merged
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
28 changes: 24 additions & 4 deletions tests/realtikvtest/txntest/stale_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,34 @@ func TestStalenessAndHistoryRead(t *testing.T) {
ON DUPLICATE KEY
UPDATE variable_value = '%[2]s', comment = '%[3]s'`, safePointName, safePointValue, safePointComment)
tk.MustExec(updateSafePoint)
time1 := time.Now()
getCurrentTS := func() uint64 {
tk.MustExec("begin")
tsStr := tk.MustQuery("select @@tidb_current_ts").Rows()[0][0].(string)
tk.MustExec("rollback")
ts, err := strconv.ParseUint(tsStr, 10, 64)
require.NoError(t, err)
return ts
}
waitTSAfter := func(after time.Time) time.Time {
for {
ts := getCurrentTS()
tsTime := oracle.GetTimeFromTS(ts)
if tsTime.After(after) {
return tsTime
}
time.Sleep(10 * time.Millisecond)
}
}
time1 := oracle.GetTimeFromTS(getCurrentTS())
time1TS := oracle.GoTimeToTS(time1)
schemaVer1 := tk.Session().GetInfoSchema().SchemaMetaVersion()
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int primary key);")
tk.MustExec(`drop table if exists t`)
time.Sleep(1000 * time.Millisecond)
time2 := time.Now().Add(-500 * time.Millisecond)
lastCommitTSStr := tk.MustQuery("select json_extract(@@tidb_last_txn_info, '$.commit_ts')").Rows()[0][0].(string)
lastCommitTS, err := strconv.ParseUint(lastCommitTSStr, 10, 64)
require.NoError(t, err)
time2 := waitTSAfter(oracle.GetTimeFromTS(lastCommitTS))
time2TS := oracle.GoTimeToTS(time2)
schemaVer2 := tk.Session().GetInfoSchema().SchemaMetaVersion()

Expand Down Expand Up @@ -450,7 +470,7 @@ func TestStalenessAndHistoryRead(t *testing.T) {
require.Equal(t, time2TS, tk.Session().GetSessionVars().TxnCtx.StartTS)
require.Nil(t, tk.Session().GetSessionVars().SnapshotInfoschema)
require.Equal(t, schemaVer2, tk.Session().GetInfoSchema().SchemaMetaVersion())
err := tk.ExecToErr(`set @@tidb_snapshot="2020-10-08 16:45:26";`)
err = tk.ExecToErr(`set @@tidb_snapshot="2020-10-08 16:45:26";`)
require.Regexp(t, ".*Transaction characteristics can't be changed while a transaction is in progress", err.Error())
require.Equal(t, uint64(0), tk.Session().GetSessionVars().SnapshotTS)
require.Nil(t, tk.Session().GetSessionVars().SnapshotInfoschema)
Expand Down