Greg Sabino Mullane wrote at 2026-03-09 22:07:
I don't think your new test is really testing the full functionality
of \watch min, but I agree that existing test does not either. How
about something like this?
select now() as start \gset
with x as (select now() - :'start' as howlong)
select 123 from x where howlong < '0.5 second' \watch i=0.2 m=1
Yeah, your query fits the spirit of the test more and doesn't fail
with modified post_auth_delay. We would expect 3 rows with
this wait interval and '0.5 second' limit, but on really slow
machines we could wait more than 0.2 seconds between watches and
the test would still fail
Maybe we could use sequences since we need a query that could
self-terminate, like in attached?
Regards,
Oleg
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index 6839f27cbe5..d821cd0c234 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -398,14 +398,11 @@ 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),
- qr/^123$/,
- '\watch, 2 minimum rows');
+ q{CREATE SEQUENCE watch_test;
+ WITH x AS (SELECT nextval('watch_test') > 3 AS seq_limit_reached)
+ SELECT 123 FROM x WHERE NOT seq_limit_reached \watch i=0.2 m=1},
+ qr/^123\n123\n123$/,
+ '\watch, check that minimum rows option works');
# Check \watch errors
psql_fails_like(
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,