Skip to content

Commit

Permalink
executor: add test for issue 55500 and it has been fixed by pingcap#5…
Browse files Browse the repository at this point in the history
…3489 (pingcap#55503)

Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Aug 26, 2024
1 parent d36d14a commit 8c7e495
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"math"
"math/rand"
"path/filepath"
"reflect"
"runtime"
Expand Down Expand Up @@ -6441,3 +6442,64 @@ func TestIssue51324(t *testing.T) {
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1364 Field 'a' doesn't have a default value", "Warning 1364 Field 'b' doesn't have a default value", "Warning 1364 Field 'c' doesn't have a default value", "Warning 1364 Field 'd' doesn't have a default value"))
tk.MustQuery("select * from t order by id").Check(testkit.Rows("13 <nil> <nil> 0 0", "21 1 <nil> 0 1", "22 1 <nil> 0 1"))
}

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()
}

0 comments on commit 8c7e495

Please sign in to comment.