(t *testing.T)
| 2827 | } |
| 2828 | |
| 2829 | func TestConnCancelRequest(t *testing.T) { |
| 2830 | t.Parallel() |
| 2831 | |
| 2832 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 2833 | defer cancel() |
| 2834 | |
| 2835 | pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE")) |
| 2836 | require.NoError(t, err) |
| 2837 | defer closeConn(t, pgConn) |
| 2838 | |
| 2839 | if pgConn.ParameterStatus("crdb_version") != "" { |
| 2840 | t.Skip("Server does not support query cancellation (https://github.com/cockroachdb/cockroach/issues/41335)") |
| 2841 | } |
| 2842 | |
| 2843 | multiResult := pgConn.Exec(ctx, "select 'Hello, world', pg_sleep(25)") |
| 2844 | |
| 2845 | errChan := make(chan error) |
| 2846 | go func() { |
| 2847 | // The query is actually sent when multiResult.NextResult() is called. So wait to ensure it is sent. |
| 2848 | // Once Flush is available this could use that instead. |
| 2849 | time.Sleep(1 * time.Second) |
| 2850 | |
| 2851 | err := pgConn.CancelRequest(ctx) |
| 2852 | errChan <- err |
| 2853 | }() |
| 2854 | |
| 2855 | for multiResult.NextResult() { |
| 2856 | } |
| 2857 | err = multiResult.Close() |
| 2858 | |
| 2859 | require.IsType(t, &pgconn.PgError{}, err) |
| 2860 | require.Equal(t, "57014", err.(*pgconn.PgError).Code) |
| 2861 | |
| 2862 | err = <-errChan |
| 2863 | require.NoError(t, err) |
| 2864 | |
| 2865 | ensureConnValid(t, pgConn) |
| 2866 | } |
| 2867 | |
| 2868 | // https://github.com/jackc/pgx/issues/659 |
| 2869 | func TestConnContextCanceledCancelsRunningQueryOnServer(t *testing.T) { |
nothing calls this directly
no test coverage detected