postgres.git / summary / log / commit / refs

commit    21ada43a6105bee3093d636d2ba2afc71bebe5a1
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Thu Sep 25 17:29:02 2025 +0000
First released in: 15.15, 16.11, 17.7, 18.1

    Add minimal sleep to stats isolation test functions.
    
    The functions test_stat_func() and test_stat_func2() had empty
    function bodies, so that they took very little time to run.  This made
    it possible that on machines with relatively low timer resolution the
    functions could return before the clock advanced, making the test fail
    (as seen on buildfarm members fruitcrow and hamerkop).
    
    To avoid that, pg_sleep for 10us during the functions.  As far as we
    can tell, all current hardware has clock resolution much less than
    that.  (The current implementation of pg_sleep will round it up to
    1ms anyway, but someday that might get improved.)
    
    Author: Michael Banck <mbanck@gmx.net>
    Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
    Discussion: https://postgr.es/m/68d413a3.a70a0220.24c74c.8be9@mx.google.com
    Backpatch-through: 15


src/test/isolation/specs/stats.spec | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/isolation/specs/stats.spec b/src/test/isolation/specs/stats.spec index 5b922d788cc..64247c40875 100644 --- a/src/test/isolation/specs/stats.spec +++ b/src/test/isolation/specs/stats.spec @@ -6,10 +6,13 @@ setup INSERT INTO test_stat_tab(key, value) VALUES('k0', 1); INSERT INTO test_stat_oid(name, oid) VALUES('test_stat_tab', 'test_stat_tab'::regclass); - CREATE FUNCTION test_stat_func() RETURNS VOID LANGUAGE plpgsql AS $$BEGIN END;$$; + -- include 10us sleep to ensure that runtime measures as more than zero + CREATE FUNCTION test_stat_func() RETURNS VOID LANGUAGE plpgsql AS + $$BEGIN PERFORM pg_sleep(10e-6); END;$$; INSERT INTO test_stat_oid(name, oid) VALUES('test_stat_func', 'test_stat_func'::regproc); - CREATE FUNCTION test_stat_func2() RETURNS VOID LANGUAGE plpgsql AS $$BEGIN END;$$; + CREATE FUNCTION test_stat_func2() RETURNS VOID LANGUAGE plpgsql AS + $$BEGIN PERFORM pg_sleep(10e-6); END;$$; INSERT INTO test_stat_oid(name, oid) VALUES('test_stat_func2', 'test_stat_func2'::regproc); CREATE TABLE test_slru_stats(slru TEXT, stat TEXT, value INT); [parent: a54c7a1133a4]