mirror of https://github.com/jackc/pgx.git
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.pull/1708/head
parent
1a9b2a53a5
commit
d626dfe94e
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -331,6 +332,7 @@ func TestConnConcurrency(t *testing.T) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
concurrency := 50
|
concurrency := 50
|
||||||
|
errChan := make(chan error, concurrency)
|
||||||
|
|
||||||
for i := 1; i <= concurrency; i++ {
|
for i := 1; i <= concurrency; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
@ -344,14 +346,29 @@ func TestConnConcurrency(t *testing.T) {
|
||||||
str := strconv.Itoa(idx)
|
str := strconv.Itoa(idx)
|
||||||
duration := time.Duration(idx) * time.Second
|
duration := time.Duration(idx) * time.Second
|
||||||
_, err := db.ExecContext(ctx, "insert into t values($1)", idx)
|
_, err := db.ExecContext(ctx, "insert into t values($1)", idx)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
errChan <- fmt.Errorf("insert failed: %d %w", idx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
_, err = db.ExecContext(ctx, "update t set str = $1 where id = $2", str, idx)
|
_, err = db.ExecContext(ctx, "update t set str = $1 where id = $2", str, idx)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
errChan <- fmt.Errorf("update 1 failed: %d %w", idx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
_, err = db.ExecContext(ctx, "update t set dur_str = $1 where id = $2", duration, idx)
|
_, err = db.ExecContext(ctx, "update t set dur_str = $1 where id = $2", duration, idx)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
errChan <- fmt.Errorf("update 2 failed: %d %w", idx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
errChan <- nil
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
for i := 1; i <= concurrency; i++ {
|
||||||
|
err := <-errChan
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
for i := 1; i <= concurrency; i++ {
|
for i := 1; i <= concurrency; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
@ -366,7 +383,10 @@ func TestConnConcurrency(t *testing.T) {
|
||||||
var str string
|
var str string
|
||||||
var duration pgtype.Interval
|
var duration pgtype.Interval
|
||||||
err := db.QueryRowContext(ctx, "select id,str,dur_str from t where id = $1", idx).Scan(&id, &str, &duration)
|
err := db.QueryRowContext(ctx, "select id,str,dur_str from t where id = $1", idx).Scan(&id, &str, &duration)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
errChan <- fmt.Errorf("select failed: %d %w", idx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
require.Equal(t, idx, id)
|
require.Equal(t, idx, id)
|
||||||
require.Equal(t, strconv.Itoa(idx), str)
|
require.Equal(t, strconv.Itoa(idx), str)
|
||||||
expectedDuration := pgtype.Interval{
|
expectedDuration := pgtype.Interval{
|
||||||
|
@ -374,9 +394,15 @@ func TestConnConcurrency(t *testing.T) {
|
||||||
Valid: true,
|
Valid: true,
|
||||||
}
|
}
|
||||||
require.Equal(t, expectedDuration, duration)
|
require.Equal(t, expectedDuration, duration)
|
||||||
|
|
||||||
|
errChan <- nil
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
for i := 1; i <= concurrency; i++ {
|
||||||
|
err := <-errChan
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue