psql's 001_basic.pl test could fail on very slow machines

Поиск
Список
Период
Сортировка
Искать

psql's 001_basic.pl test could fail on very slow machines

От:
Oleg Tselebrovskiy <o.tselebrovskiy@postgrespro.ru>
Дата:
Вложения:
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)

Re: psql's 001_basic.pl test could fail on very slow machines

От:
Greg Sabino Mullane <htamfids@gmail.com>
Дата:
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

Cheers,
Greg

Re: psql's 001_basic.pl test could fail on very slow machines

От:
Oleg Tselebrovskiy <o.tselebrovskiy@postgrespro.ru>
Дата:
Вложения:
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

Re: psql's 001_basic.pl test could fail on very slow machines

От:
Greg Sabino Mullane <htamfids@gmail.com>
Дата:
On Tue, Mar 10, 2026 at 7:01 AM Oleg Tselebrovskiy <o.tselebrovskiy@postgrespro.ru> wrote:
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

The test should still pass. I'm not worried about how many rows appear, just that they appear and then stop appearing once the criteria is met.
 
Maybe we could use sequences since we need a query that could self-terminate, like in attached?

Yes, I like this one better. +1

Inlining it here as it's so small:

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



Cheers,
Greg

FAQ