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

Function TestConnExecBatchPrecanceled

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

Source from the content-addressed store, hash-verified

1897}
1898
1899func TestConnExecBatchPrecanceled(t *testing.T) {
1900 t.Parallel()
1901
1902 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1903 defer cancel()
1904
1905 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1906 require.NoError(t, err)
1907 defer closeConn(t, pgConn)
1908
1909 _, err = pgConn.Prepare(ctx, "ps1", "select $1::text", nil)
1910 require.NoError(t, err)
1911
1912 batch := &pgconn.Batch{}
1913
1914 batch.ExecParams("select $1::text", [][]byte{[]byte("ExecParams 1")}, nil, nil, nil)
1915 batch.ExecPrepared("ps1", [][]byte{[]byte("ExecPrepared 1")}, nil, nil)
1916 batch.ExecParams("select $1::text", [][]byte{[]byte("ExecParams 2")}, nil, nil, nil)
1917
1918 cancel()
1919 _, err = pgConn.ExecBatch(ctx, batch).ReadAll()
1920 require.Error(t, err)
1921 assert.True(t, errors.Is(err, context.Canceled))
1922 assert.True(t, pgconn.SafeToRetry(err))
1923
1924 ensureConnValid(t, pgConn)
1925}
1926
1927// Without concurrent reading and writing large batches can deadlock.
1928//

Callers

nothing calls this directly

Calls 10

ExecParamsMethod · 0.95
ExecPreparedMethod · 0.95
ConnectFunction · 0.92
SafeToRetryFunction · 0.92
ReadAllMethod · 0.80
ExecBatchMethod · 0.80
closeConnFunction · 0.70
ensureConnValidFunction · 0.70
PrepareMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected