diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-03-18 13:14:55 +0100 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-03-18 13:14:55 +0100 |
commit | 6b3678d3474ff456b3229e4829c595be1c0c2888 (patch) | |
tree | 2554710fcb91004c8f77e4d4cc0004735402c7f6 /src | |
parent | 0960ae1967d0569be4d118c20e51a2ed98d76f65 (diff) | |
download | postgresql-6b3678d3474ff456b3229e4829c595be1c0c2888.tar.gz postgresql-6b3678d3474ff456b3229e4829c595be1c0c2888.zip |
Put libpq_pipeline cancel test back
I disabled it in cc6e64afda53 because it was unstable; hopefully the
changes here make it more stable. (Jelte proposed to submit the queries
using simple query protocol, but I chose to instead make the monitor
connection wait until the PgSleep wait event is seen. This is probably
not a terribly meaningful increase in coverage ...)
Discussion: https://postgr.es/m/CAGECzQRQh_5tSy+5cndgv08eNJ2O0Zpwn2YddJtSsmC=Wpy1BQ@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r-- | src/test/modules/libpq_pipeline/libpq_pipeline.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index e730ad37698..b7e7a0947cb 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -116,27 +116,37 @@ confirm_query_canceled_impl(int line, PGconn *conn) /* * Using monitorConn, query pg_stat_activity to see that the connection with - * the given PID is in the given state. We never stop until it does. + * the given PID is either in the given state, or waiting on the given event + * (only one of them can be given). */ static void -wait_for_connection_state(int line, PGconn *monitorConn, int procpid, char *state) +wait_for_connection_state(int line, PGconn *monitorConn, int procpid, + char *state, char *event) { const Oid paramTypes[] = {INT4OID, TEXTOID}; const char *paramValues[2]; char *pidstr = psprintf("%d", procpid); + Assert((state == NULL) ^ (event == NULL)); + paramValues[0] = pidstr; - paramValues[1] = state; + paramValues[1] = state ? state : event; while (true) { PGresult *res; char *value; - res = PQexecParams(monitorConn, - "SELECT count(*) FROM pg_stat_activity WHERE " - "pid = $1 AND state = $2", - 2, paramTypes, paramValues, NULL, NULL, 1); + if (state != NULL) + res = PQexecParams(monitorConn, + "SELECT count(*) FROM pg_stat_activity WHERE " + "pid = $1 AND state = $2", + 2, paramTypes, paramValues, NULL, NULL, 0); + else + res = PQexecParams(monitorConn, + "SELECT count(*) FROM pg_stat_activity WHERE " + "pid = $1 AND wait_event = $2", + 2, paramTypes, paramValues, NULL, NULL, 0); if (PQresultStatus(res) != PGRES_TUPLES_OK) pg_fatal_impl(line, "could not query pg_stat_activity: %s", PQerrorMessage(monitorConn)); @@ -145,7 +155,7 @@ wait_for_connection_state(int line, PGconn *monitorConn, int procpid, char *stat if (PQnfields(res) != 1) pg_fatal_impl(line, "unexpected number of columns received: %d", PQnfields(res)); value = PQgetvalue(res, 0, 0); - if (value[0] != '0') + if (strcmp(value, "0") != 0) { PQclear(res); break; @@ -172,7 +182,7 @@ send_cancellable_query_impl(int line, PGconn *conn, PGconn *monitorConn) * connection below is reliable, instead of possibly seeing an outdated * state. */ - wait_for_connection_state(line, monitorConn, PQbackendPID(conn), "idle"); + wait_for_connection_state(line, monitorConn, PQbackendPID(conn), "idle", NULL); env_wait = getenv("PG_TEST_TIMEOUT_DEFAULT"); if (env_wait == NULL) @@ -183,10 +193,10 @@ send_cancellable_query_impl(int line, PGconn *conn, PGconn *monitorConn) pg_fatal_impl(line, "failed to send query: %s", PQerrorMessage(conn)); /* - * Wait for the query to start, because if the query is not running yet - * the cancel request that we send won't have any effect. + * Wait for the sleep to be active, because if the query is not running + * yet, the cancel request that we send won't have any effect. */ - wait_for_connection_state(line, monitorConn, PQbackendPID(conn), "active"); + wait_for_connection_state(line, monitorConn, PQbackendPID(conn), NULL, "PgSleep"); } /* @@ -2098,10 +2108,7 @@ usage(const char *progname) static void print_test_list(void) { -#if 0 - /* Commented out until further stabilized */ printf("cancel\n"); -#endif printf("disallowed_in_pipeline\n"); printf("multi_pipelines\n"); printf("nosync\n"); |