fix: fix ignored scanner.Err() (#4063)

This commit is contained in:
Kevin Wan 2024-04-10 17:28:52 +08:00 committed by GitHub
parent a66ae0d4c4
commit 682460c1c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -248,7 +248,7 @@ func unmarshalRows(v any, scanner rowsScanner, strict bool) error {
return ErrUnsupportedValueType return ErrUnsupportedValueType
} }
return nil return scanner.Err()
default: default:
return ErrUnsupportedValueType return ErrUnsupportedValueType
} }

View File

@ -291,19 +291,19 @@ func TestStmtBreaker(t *testing.T) {
}) })
} }
func TestQueryScanTimeout(t *testing.T) { func TestQueryRowsScanTimeout(t *testing.T) {
dbtest.RunTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) { dbtest.RunTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond) rows := sqlmock.NewRows([]string{"foo"})
defer cancel()
row := sqlmock.NewRows([]string{"foo"})
for i := 0; i < 10000; i++ { for i := 0; i < 10000; i++ {
row = row.AddRow("bar" + strconv.Itoa(i)) rows = rows.AddRow("bar" + strconv.Itoa(i))
} }
mock.ExpectQuery("any").WillReturnRows(rows)
var val []struct { var val []struct {
Foo int Foo string
Bar string
} }
conn := NewSqlConnFromDB(db) conn := NewSqlConnFromDB(db)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
err := conn.QueryRowsCtx(ctx, &val, "any") err := conn.QueryRowsCtx(ctx, &val, "any")
assert.ErrorIs(t, err, context.DeadlineExceeded) assert.ErrorIs(t, err, context.DeadlineExceeded)
}) })