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

Function TestConnExecBatchWriteError

pgconn/pgconn_test.go:1826–1860  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1824}
1825
1826func TestConnExecBatchWriteError(t *testing.T) {
1827 t.Parallel()
1828
1829 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1830 defer cancel()
1831
1832 config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
1833 require.NoError(t, err)
1834
1835 var mockConn mockConnection
1836 writeLatency := 0 * time.Second
1837 config.DialFunc = func(ctx context.Context, network, address string) (net.Conn, error) {
1838 conn, err := net.Dial(network, address)
1839 mockConn = mockConnection{conn, &writeLatency}
1840 return mockConn, err
1841 }
1842
1843 pgConn, err := pgconn.ConnectConfig(ctx, config)
1844 require.NoError(t, err)
1845 defer closeConn(t, pgConn)
1846
1847 batch := &pgconn.Batch{}
1848 pgConn.Conn()
1849
1850 ctx2, cancel2 := context.WithTimeout(context.Background(), 1*time.Second)
1851 defer cancel2()
1852
1853 batch.ExecParams("select $1::text", [][]byte{[]byte("ExecParams 1")}, nil, nil, nil)
1854 writeLatency = 2 * time.Second
1855 mrr := pgConn.ExecBatch(ctx2, batch)
1856 err = mrr.Close()
1857 require.Error(t, err)
1858 assert.ErrorIs(t, err, context.DeadlineExceeded)
1859 require.True(t, pgConn.IsClosed())
1860}
1861
1862func TestConnExecBatchDeferredError(t *testing.T) {
1863 t.Parallel()

Callers

nothing calls this directly

Calls 9

ExecParamsMethod · 0.95
ParseConfigFunction · 0.92
ConnectConfigFunction · 0.92
ExecBatchMethod · 0.80
closeConnFunction · 0.70
ConnMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45
IsClosedMethod · 0.45

Tested by

no test coverage detected