MCPcopy
hub / github.com/jackc/pgx / TestPoolSendBatchBatchCloseTwice

Function TestPoolSendBatchBatchCloseTwice

pgxpool/pool_test.go:1230–1283  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1228}
1229
1230func TestPoolSendBatchBatchCloseTwice(t *testing.T) {
1231 t.Parallel()
1232
1233 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1234 defer cancel()
1235
1236 pool, err := pgxpool.New(ctx, os.Getenv("PGX_TEST_DATABASE"))
1237 require.NoError(t, err)
1238 defer pool.Close()
1239
1240 errChan := make(chan error)
1241 testCount := 5000
1242
1243 for range testCount {
1244 go func() {
1245 batch := &pgx.Batch{}
1246 batch.Queue("select 1")
1247 batch.Queue("select 2")
1248
1249 br := pool.SendBatch(ctx, batch)
1250 defer br.Close()
1251
1252 var err error
1253 var n int32
1254 err = br.QueryRow().Scan(&n)
1255 if err != nil {
1256 errChan <- err
1257 return
1258 }
1259 if n != 1 {
1260 errChan <- fmt.Errorf("expected 1 got %v", n)
1261 return
1262 }
1263
1264 err = br.QueryRow().Scan(&n)
1265 if err != nil {
1266 errChan <- err
1267 return
1268 }
1269 if n != 2 {
1270 errChan <- fmt.Errorf("expected 2 got %v", n)
1271 return
1272 }
1273
1274 err = br.Close()
1275 errChan <- err
1276 }()
1277 }
1278
1279 for range testCount {
1280 err := <-errChan
1281 assert.NoError(t, err)
1282 }
1283}
1284
1285func TestPoolAcquireDestroysExpiredIdleConn(t *testing.T) {
1286 t.Parallel()

Callers

nothing calls this directly

Calls 6

QueueMethod · 0.95
NewFunction · 0.92
CloseMethod · 0.65
SendBatchMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected