Hi hackers, When building with -DUSE_VALGRIND, tests run significantly slower due to Valgrind's instrumentation overhead, causing the default 1000s test's timeout to be exceeded. Example when running the regress test suite:
" $ meson test -C build -q --print-errorlogs --setup running --suite regress-running regress-running - postgresql:regress-running/regress time out (After 1000 seconds) Summary of Failures: 1/1 regress-running - postgresql:regress-running/regress TIMEOUT 1000.01s Ok: 0 Fail: 0 Timeout: 1 " PFA a patch that detects Valgrind builds using a compiler check, which correctly handles USE_VALGRIND being passed via -Dc_args, CPPFLAGS or CFLAGS and increases the test timeout to 10000s in that case. I don't have a strong opinion on the new value. In practice, the regress suite runs in about 30 seconds without Valgrind and in about 46 minutes with Valgrind on my setup. Note that the timeout is per test, not for the entire suite so that 10000s looks large enough (I tested to run the entire suite with the patch and it did not produce any timeout). Another option could be to disable the timeout on a Valgrind build (set timeout to 0) but then a test could block forever. Note that there are no changes needed for autoconf as it does not set a timeout for the tests. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
>From 27379c12d3bddfb15c383fe808eb8d966097ca61 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Fri, 3 Apr 2026 10:17:21 +0000 Subject: [PATCH v1] meson: adjust test timeout for Valgrind builds When building with -DUSE_VALGRIND, tests run significantly slower due to Valgrind's instrumentation overhead, causing the default 1000s timeout to be exceeded. This commit detects Valgrind builds using a compiler check, which correctly handles USE_VALGRIND being passed via -Dc_args, CPPFLAGS or CFLAGS and increases the test timeout to 10000s in that case. No changes are needed for autoconf as it has no test timeout mechanism. Author: Bertrand Drouvot <[email protected]> Discussion: https://postgr.es/m/ --- meson.build | 10 ++++++++-- src/test/isolation/meson.build | 8 +++++++- src/test/regress/meson.build | 7 ++++++- 3 files changed, 21 insertions(+), 4 deletions(-) 29.3% src/test/isolation/ 29.2% src/test/regress/ diff --git a/meson.build b/meson.build index 6bc74c2ba79..7d376495e20 100644 --- a/meson.build +++ b/meson.build @@ -3888,6 +3888,12 @@ install_suites = [] testwrap = files('src/tools/testwrap') +# Detect if built with Valgrind support to adjust test timeouts +is_valgrind_build = cc.compiles(''' +#ifndef USE_VALGRIND +choke me +#endif''', name: 'USE_VALGRIND check', args: test_c_args) + foreach test_dir : tests testwrap_base = [ testwrap, @@ -3955,7 +3961,7 @@ foreach test_dir : tests test_kwargs = { 'protocol': 'tap', 'priority': 10, - 'timeout': 1000, + 'timeout': is_valgrind_build ? 10000 : 1000, 'depends': test_deps + t.get('deps', []), 'env': env, } + t.get('test_kwargs', {}) @@ -4028,7 +4034,7 @@ foreach test_dir : tests test_kwargs = { 'protocol': 'tap', 'suite': test_group, - 'timeout': 1000, + 'timeout': is_valgrind_build ? 10000 : 1000, 'depends': test_deps + t.get('deps', []), 'env': env, } + t.get('test_kwargs', {}) diff --git a/src/test/isolation/meson.build b/src/test/isolation/meson.build index c55b8d71848..87786dacf81 100644 --- a/src/test/isolation/meson.build +++ b/src/test/isolation/meson.build @@ -59,6 +59,12 @@ isolationtester = executable('isolationtester', ) bin_targets += isolationtester +# Detect if built with Valgrind support to adjust test timeouts +is_valgrind_build = cc.compiles(''' +#ifndef USE_VALGRIND +choke me +#endif''', name: 'USE_VALGRIND check') + tests += { 'name': 'isolation', 'sd': meson.current_source_dir(), @@ -67,7 +73,7 @@ tests += { 'schedule': files('isolation_schedule'), 'test_kwargs': { 'priority': 40, - 'timeout': 1000, + 'timeout': is_valgrind_build ? 10000 : 1000, }, 'dbname': 'isolation_regression', }, diff --git a/src/test/regress/meson.build b/src/test/regress/meson.build index a5f2222e83a..196cf263c6d 100644 --- a/src/test/regress/meson.build +++ b/src/test/regress/meson.build @@ -43,6 +43,11 @@ regress_module = shared_module('regress', ) test_install_libs += regress_module +# Detect if built with Valgrind support to adjust test timeouts +is_valgrind_build = cc.compiles(''' +#ifndef USE_VALGRIND +choke me +#endif''', name: 'USE_VALGRIND check') tests += { 'name': 'regress', @@ -52,7 +57,7 @@ tests += { 'schedule': files('parallel_schedule'), 'test_kwargs': { 'priority': 50, - 'timeout': 1000, + 'timeout': is_valgrind_build ? 10000 : 1000, }, 'dbname': 'regression', }, -- 2.34.1
