-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgbouncer_test.go
76 lines (62 loc) · 2.06 KB
/
pgbouncer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package pgx_test
import (
"context"
"os"
"testing"
"github.com/jackc/pgx/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPgbouncerStatementCacheDescribe(t *testing.T) {
connString := os.Getenv("PGX_TEST_PGBOUNCER_CONN_STRING")
if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_PGBOUNCER_CONN_STRING")
}
config := mustParseConfig(t, connString)
config.DefaultQueryExecMode = pgx.QueryExecModeCacheDescribe
config.DescriptionCacheCapacity = 1024
testPgbouncer(t, config, 10, 100)
}
func TestPgbouncerSimpleProtocol(t *testing.T) {
connString := os.Getenv("PGX_TEST_PGBOUNCER_CONN_STRING")
if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_PGBOUNCER_CONN_STRING")
}
config := mustParseConfig(t, connString)
config.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol
testPgbouncer(t, config, 10, 100)
}
func testPgbouncer(t *testing.T, config *pgx.ConnConfig, workers, iterations int) {
doneChan := make(chan struct{})
for i := 0; i < workers; i++ {
go func() {
defer func() { doneChan <- struct{}{} }()
conn, err := pgx.ConnectConfig(context.Background(), config)
require.Nil(t, err)
defer closeConn(t, conn)
for i := 0; i < iterations; i++ {
var i32 int32
var i64 int64
var f32 float32
var s string
var s2 string
err = conn.QueryRow(context.Background(), "select 1::int4, 2::int8, 3::float4, 'hi'::text").Scan(&i32, &i64, &f32, &s)
require.NoError(t, err)
assert.Equal(t, int32(1), i32)
assert.Equal(t, int64(2), i64)
assert.Equal(t, float32(3), f32)
assert.Equal(t, "hi", s)
err = conn.QueryRow(context.Background(), "select 1::int8, 2::float4, 'bye'::text, 4::int4, 'whatever'::text").Scan(&i64, &f32, &s, &i32, &s2)
require.NoError(t, err)
assert.Equal(t, int64(1), i64)
assert.Equal(t, float32(2), f32)
assert.Equal(t, "bye", s)
assert.Equal(t, int32(4), i32)
assert.Equal(t, "whatever", s2)
}
}()
}
for i := 0; i < workers; i++ {
<-doneChan
}
}