psql's 001_basic.pl test could fail on very slow machines
Greetings, everyone!
I've gotten a very-very rare failure of psql's 001_basic.pl:
# +++ tap check in src/bin/psql +++
t/001_basic.pl ................. 79/?
# Failed test '\watch, 2 minimum rows: matches'
# at t/001_basic.pl line 380.
# ''
# doesn't match '(?^l:^123$)'
# Looks like you failed 1 test of 110.
t/001_basic.pl ................. Dubious, test returned 1 (wstat 256,
0x100)
Failed 1/110 subtests
The failed query itself:
psql_like(
$node,
sprintf(
q{with x as (
select now()-backend_start AS howlong
from pg_stat_activity
where pid = pg_backend_pid()
) select 123 from x where howlong < '2 seconds' \watch i=%g m=2},
0.5),
qr/^123$/,
'\watch, 2 minimum rows');
It seems that on very slow machines time between backend's start and
actual query execution can be more than two seconds
You can reproduce something similar with first attached patch,
manual_reproduction, using post_auth_delay
This can be reproduced on 17+ since this is when m[in_rows] was
introduced
Since this test checks that "\watch" clause "m[in_rows]" stops query
execution if amount of rows is less than the value of m,
we could simplify the test by replacing pg_stat_activity access
with plain select (see second attached patch, rewrite_test)diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index 6839f27cbe5..f165b196110 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -396,6 +396,9 @@ psql_fails_like(
qr/minimum row count specified more than once/,
'\watch, minimum rows is specified more than once');
+$node->append_conf('postgresql.conf', 'post_auth_delay=3');
+$node->reload();
+
psql_like(
$node,
sprintf(
@@ -407,6 +410,9 @@ psql_like(
qr/^123$/,
'\watch, 2 minimum rows');
+$node->append_conf('postgresql.conf', 'post_auth_delay=0');
+$node->reload();
+
# Check \watch errors
psql_fails_like(
$node,
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index 6839f27cbe5..1f1c4d1a939 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -398,12 +398,7 @@ psql_fails_like(
psql_like(
$node,
- sprintf(
- q{with x as (
- select now()-backend_start AS howlong
- from pg_stat_activity
- where pid = pg_backend_pid()
- ) select 123 from x where howlong < '2 seconds' \watch i=%g m=2}, 0.5),
+ 'SELECT 123 \watch m=2',
qr/^123$/,
'\watch, 2 minimum rows');