Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#55503
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
crazycs520 authored and ti-chi-bot committed Sep 12, 2024
1 parent 5665343 commit ba7eaf0
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions pkg/executor/test/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import (
"archive/zip"
"context"
"fmt"
<<<<<<< HEAD
"math"
=======
"math/rand"
"os"
>>>>>>> 45b127d96ab (executor: add test for issue 55500 and it has been fixed by #53489 (#55503))
"path/filepath"
"reflect"
"runtime"
Expand Down Expand Up @@ -4472,3 +4477,83 @@ func TestIssue48756(t *testing.T) {
"Warning 1105 ",
))
}
<<<<<<< HEAD
=======

func TestIssue50308(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a timestamp);")
tk.MustExec("insert ignore into t values(cast('2099-01-01' as date));")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning 1292 Incorrect timestamp value: '2099-01-01' for column 'a' at row 1"))
tk.MustQuery("select * from t;").Check(testkit.Rows("0000-00-00 00:00:00"))
tk.MustExec("delete from t")
tk.MustExec("insert into t values('2000-01-01');")
tk.MustGetErrMsg("update t set a=cast('2099-01-01' as date)", "[types:1292]Incorrect timestamp value: '2099-01-01'")
tk.MustExec("update ignore t set a=cast('2099-01-01' as date);")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning 1292 Incorrect timestamp value: '2099-01-01'"))
tk.MustQuery("select * from t;").Check(testkit.Rows("0000-00-00 00:00:00"))
}

func TestQueryWithKill(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists tkq;")
tk.MustExec("create table tkq (a int key, b int, index idx_b(b));")
tk.MustExec("insert into tkq values (1,1);")
var wg sync.WaitGroup
ch := make(chan context.CancelFunc, 1024)
testDuration := time.Second * 10
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
start := time.Now()
for {
ctx, cancel := context.WithCancel(context.Background())
ch <- cancel
rs, err := tk.ExecWithContext(ctx, "select a from tkq where b = 1;")
if err == nil {
require.NotNil(t, rs)
rows, err := session.ResultSetToStringSlice(ctx, tk.Session(), rs)
if err == nil {
require.Equal(t, 1, len(rows))
require.Equal(t, 1, len(rows[0]))
require.Equal(t, "1", fmt.Sprintf("%v", rows[0][0]))
}
}
if err != nil {
require.Equal(t, context.Canceled, err)
}
if rs != nil {
rs.Close()
}
if time.Since(start) > testDuration {
return
}
}
}()
}
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case cancel := <-ch:
// mock for random kill query
if len(ch) < 5 {
time.Sleep(time.Duration(rand.Intn(1000)) * time.Nanosecond)
}
cancel()
case <-time.After(time.Second):
return
}
}
}()
wg.Wait()
}
>>>>>>> 45b127d96ab (executor: add test for issue 55500 and it has been fixed by #53489 (#55503))

0 comments on commit ba7eaf0

Please sign in to comment.