@@ -116,27 +116,37 @@ confirm_query_canceled_impl(int line, PGconn *conn)
116
116
117
117
/*
118
118
* Using monitorConn, query pg_stat_activity to see that the connection with
119
- * the given PID is in the given state. We never stop until it does.
119
+ * the given PID is either in the given state, or waiting on the given event
120
+ * (only one of them can be given).
120
121
*/
121
122
static void
122
- wait_for_connection_state (int line ,PGconn * monitorConn ,int procpid ,char * state )
123
+ wait_for_connection_state (int line ,PGconn * monitorConn ,int procpid ,
124
+ char * state ,char * event )
123
125
{
124
126
const Oid paramTypes []= {INT4OID ,TEXTOID };
125
127
const char * paramValues [2 ];
126
128
char * pidstr = psprintf ("%d" ,procpid );
127
129
130
+ Assert ((state == NULL ) ^ (event == NULL ));
131
+
128
132
paramValues [0 ]= pidstr ;
129
- paramValues [1 ]= state ;
133
+ paramValues [1 ]= state ? state : event ;
130
134
131
135
while (true)
132
136
{
133
137
PGresult * res ;
134
138
char * value ;
135
139
136
- res = PQexecParams (monitorConn ,
137
- "SELECT count(*) FROM pg_stat_activity WHERE "
138
- "pid = $1 AND state = $2" ,
139
- 2 ,paramTypes ,paramValues ,NULL ,NULL ,1 );
140
+ if (state != NULL )
141
+ res = PQexecParams (monitorConn ,
142
+ "SELECT count(*) FROM pg_stat_activity WHERE "
143
+ "pid = $1 AND state = $2" ,
144
+ 2 ,paramTypes ,paramValues ,NULL ,NULL ,0 );
145
+ else
146
+ res = PQexecParams (monitorConn ,
147
+ "SELECT count(*) FROM pg_stat_activity WHERE "
148
+ "pid = $1 AND wait_event = $2" ,
149
+ 2 ,paramTypes ,paramValues ,NULL ,NULL ,0 );
140
150
141
151
if (PQresultStatus (res )!= PGRES_TUPLES_OK )
142
152
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
145
155
if (PQnfields (res )!= 1 )
146
156
pg_fatal_impl (line ,"unexpected number of columns received: %d" ,PQnfields (res ));
147
157
value = PQgetvalue (res ,0 ,0 );
148
- if (value [ 0 ] != '0' )
158
+ if (strcmp ( value , "0" ) != 0 )
149
159
{
150
160
PQclear (res );
151
161
break ;
@@ -172,7 +182,7 @@ send_cancellable_query_impl(int line, PGconn *conn, PGconn *monitorConn)
172
182
* connection below is reliable, instead of possibly seeing an outdated
173
183
* state.
174
184
*/
175
- wait_for_connection_state (line ,monitorConn ,PQbackendPID (conn ),"idle" );
185
+ wait_for_connection_state (line ,monitorConn ,PQbackendPID (conn ),"idle" , NULL );
176
186
177
187
env_wait = getenv ("PG_TEST_TIMEOUT_DEFAULT" );
178
188
if (env_wait == NULL )
@@ -183,10 +193,10 @@ send_cancellable_query_impl(int line, PGconn *conn, PGconn *monitorConn)
183
193
pg_fatal_impl (line ,"failed to send query: %s" ,PQerrorMessage (conn ));
184
194
185
195
/*
186
- * Wait for thequery tostart , because if the query is not running yet
187
- * the cancel request that we send won't have any effect.
196
+ * Wait for thesleep tobe active , because if the query is not running
197
+ *yet, the cancel request that we send won't have any effect.
188
198
*/
189
- wait_for_connection_state (line ,monitorConn ,PQbackendPID (conn ),"active " );
199
+ wait_for_connection_state (line ,monitorConn ,PQbackendPID (conn ),NULL , "PgSleep " );
190
200
}
191
201
192
202
/*
@@ -2098,10 +2108,7 @@ usage(const char *progname)
2098
2108
static void
2099
2109
print_test_list (void )
2100
2110
{
2101
- #if 0
2102
- /* Commented out until further stabilized */
2103
2111
printf ("cancel\n" );
2104
- #endif
2105
2112
printf ("disallowed_in_pipeline\n" );
2106
2113
printf ("multi_pipelines\n" );
2107
2114
printf ("nosync\n" );