(t *testing.T)
| 1897 | } |
| 1898 | |
| 1899 | func 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 | // |
nothing calls this directly
no test coverage detected