Skip to content

Commit ef9fb0f

Browse files
committed
cherry-pick pingcap#50969 to fix flaky test
1 parent 73a1a11 commit ef9fb0f

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

server/conn_stmt_test.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ import (
2020
"crypto/rand"
2121
"encoding/binary"
2222
"fmt"
23-
"io/fs"
24-
"os"
25-
"path/filepath"
26-
"strconv"
27-
"strings"
28-
"syscall"
2923
"testing"
3024

3125
"github.com/pingcap/failpoint"
@@ -554,30 +548,17 @@ func TestCursorFetchErrorInFetch(t *testing.T) {
554548

555549
tk.MustExec(fmt.Sprintf("set tidb_mem_quota_query=%d", 1))
556550

551+
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/util/chunk/get-chunk-error", "return(true)"))
552+
defer func() {
553+
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/util/chunk/get-chunk-error"))
554+
}()
555+
557556
require.NoError(t, c.Dispatch(ctx, append(
558557
appendUint32([]byte{mysql.ComStmtExecute}, uint32(stmt.ID())),
559558
mysql.CursorTypeReadOnly, 0x1, 0x0, 0x0, 0x0,
560559
)))
561560

562-
// close these disk files to produce error
563-
filepath.Walk("/proc/self/fd", func(path string, info fs.FileInfo, err error) error {
564-
if err != nil {
565-
return nil
566-
}
567-
target, err := os.Readlink(path)
568-
if err != nil {
569-
return nil
570-
}
571-
if strings.HasPrefix(target, tmpStoragePath) {
572-
fd, err := strconv.Atoi(filepath.Base(path))
573-
require.NoError(t, err)
574-
require.NoError(t, syscall.Close(fd))
575-
}
576-
return nil
577-
})
578-
579-
// it'll get "bad file descriptor", as it has been closed in the test.
580-
require.Error(t, c.Dispatch(ctx, appendUint32(appendUint32([]byte{mysql.ComStmtFetch}, uint32(stmt.ID())), 1024)))
561+
require.ErrorContains(t, c.Dispatch(ctx, appendUint32(appendUint32([]byte{mysql.ComStmtFetch}, uint32(stmt.ID())), 1024)), "fail to get chunk for test")
581562
// after getting a failed FETCH, the cursor should have been reseted
582563
require.False(t, stmt.GetCursorActive())
583564
require.Len(t, tk.Session().GetSessionVars().MemTracker.GetChildrenForTest(), 0)

util/chunk/row_container_reader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"runtime"
2020
"sync"
2121

22+
"github.com/pingcap/errors"
23+
"github.com/pingcap/failpoint"
2224
"github.com/pingcap/tidb/util/logutil"
2325
)
2426

@@ -122,6 +124,11 @@ func (reader *rowContainerReader) startWorker() {
122124

123125
for chkIdx := 0; chkIdx < reader.rc.NumChunks(); chkIdx++ {
124126
chk, err := reader.rc.GetChunk(chkIdx)
127+
failpoint.Inject("get-chunk-error", func(val failpoint.Value) {
128+
if val.(bool) {
129+
err = errors.New("fail to get chunk for test")
130+
}
131+
})
125132
if err != nil {
126133
reader.err = err
127134
return

0 commit comments

Comments
 (0)