Skip to content

Commit d626dfe

Browse files
committed
TestConnConcurrency has been failing on CI
This probably won't fix it, but at the very least we should not be running assertions in a goroutine.
1 parent 1a9b2a5 commit d626dfe

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

stdlib/sql_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"database/sql"
77
"encoding/json"
8+
"fmt"
89
"math"
910
"os"
1011
"reflect"
@@ -331,6 +332,7 @@ func TestConnConcurrency(t *testing.T) {
331332
var wg sync.WaitGroup
332333

333334
concurrency := 50
335+
errChan := make(chan error, concurrency)
334336

335337
for i := 1; i <= concurrency; i++ {
336338
wg.Add(1)
@@ -344,14 +346,29 @@ func TestConnConcurrency(t *testing.T) {
344346
str := strconv.Itoa(idx)
345347
duration := time.Duration(idx) * time.Second
346348
_, err := db.ExecContext(ctx, "insert into t values($1)", idx)
347-
require.NoError(t, err)
349+
if err != nil {
350+
errChan <- fmt.Errorf("insert failed: %d %w", idx, err)
351+
return
352+
}
348353
_, err = db.ExecContext(ctx, "update t set str = $1 where id = $2", str, idx)
349-
require.NoError(t, err)
354+
if err != nil {
355+
errChan <- fmt.Errorf("update 1 failed: %d %w", idx, err)
356+
return
357+
}
350358
_, err = db.ExecContext(ctx, "update t set dur_str = $1 where id = $2", duration, idx)
351-
require.NoError(t, err)
359+
if err != nil {
360+
errChan <- fmt.Errorf("update 2 failed: %d %w", idx, err)
361+
return
362+
}
363+
364+
errChan <- nil
352365
}(i)
353366
}
354367
wg.Wait()
368+
for i := 1; i <= concurrency; i++ {
369+
err := <-errChan
370+
require.NoError(t, err)
371+
}
355372

356373
for i := 1; i <= concurrency; i++ {
357374
wg.Add(1)
@@ -366,17 +383,26 @@ func TestConnConcurrency(t *testing.T) {
366383
var str string
367384
var duration pgtype.Interval
368385
err := db.QueryRowContext(ctx, "select id,str,dur_str from t where id = $1", idx).Scan(&id, &str, &duration)
369-
require.NoError(t, err)
386+
if err != nil {
387+
errChan <- fmt.Errorf("select failed: %d %w", idx, err)
388+
return
389+
}
370390
require.Equal(t, idx, id)
371391
require.Equal(t, strconv.Itoa(idx), str)
372392
expectedDuration := pgtype.Interval{
373393
Microseconds: int64(idx) * time.Second.Microseconds(),
374394
Valid: true,
375395
}
376396
require.Equal(t, expectedDuration, duration)
397+
398+
errChan <- nil
377399
}(i)
378400
}
379401
wg.Wait()
402+
for i := 1; i <= concurrency; i++ {
403+
err := <-errChan
404+
require.NoError(t, err)
405+
}
380406
})
381407
}
382408

0 commit comments

Comments
 (0)