Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions sync_diff_inspector/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -260,6 +261,26 @@ func TestTiDBSource(t *testing.T) {

rowIter.Close()

// Test RowIterator returns the underlying database/sql row-stream error instead of treating it as clean EOF.
rowsErr := errors.New("tidb row stream cancelled")
errorRows := sqlmock.NewRows(tableCase.rowColumns).
AddRow(tableCase.rows[0]...).
AddRow(tableCase.rows[1]...).
RowError(1, rowsErr)
mock.ExpectQuery(tableCase.rowQuery).WillReturnRows(errorRows)
rowIter, err = tidb.GetRowsIterator(ctx, tableCase.rangeInfo)
require.NoError(t, err)

columns, err := rowIter.Next()
require.NoError(t, err)
require.NotNil(t, columns)

columns, err = rowIter.Next()
require.ErrorIs(t, err, rowsErr)
require.Nil(t, columns)

rowIter.Close()

analyze := tidb.GetTableAnalyzer()
statsRows := sqlmock.NewRows([]string{"is_index", "hist_id", "bucket_id", "count", "lower_bound", "upper_bound"})
for i := 0; i < 5; i++ {
Expand Down
3 changes: 3 additions & 0 deletions sync_diff_inspector/source/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (s *TiDBRowsIterator) Next() (map[string]*dbutil.ColumnData, error) {
if s.rows.Next() {
return dbutil.ScanRow(s.rows)
}
if err := s.rows.Err(); err != nil {
return nil, errors.Trace(err)
}
return nil, nil
}

Expand Down