1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
CREATE FUNCTION _timecheck(label text, tolerated interval) RETURNS text
AS $$
DECLARE
ret TEXT;
lap INTERVAL;
rec RECORD;
BEGIN
-- We use now() here to get the time at the
-- start of the transaction, which started when
-- this function was called, so the earliest
-- possible time
SELECT now()-t lap, sf slow_factor
FROM _time INTO rec;
RAISE DEBUG 'Requested tolerance: %', tolerated;
RAISE DEBUG 'Slow factor: %', rec.slow_factor;
tolerated := tolerated * rec.slow_factor;
RAISE DEBUG 'Resulting tolerance: %', tolerated;
IF rec.lap <= tolerated THEN
ret := format(
'%s interrupted on time',
label
);
ELSE
ret := format(
'%s interrupted late: %s (%s tolerated)',
label, rec.lap, tolerated
);
END IF;
UPDATE _time SET t = clock_timestamp();
RETURN ret;
END;
$$ LANGUAGE 'plpgsql' VOLATILE;
CREATE TEMPORARY TABLE _time AS
SELECT
now() t,
COALESCE(
current_setting('test.executor_slow_factor', true),
'1'
)::float8 sf;
|