1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Use "template" data directory in tests

When running all (or just many) of our tests, a significant portion of both
CPU time and IO is spent running initdb. Most of those initdb runs don't
specify any options influencing properties of the created data directory.

Avoid most of that overhead by creating a "template" data directory, alongside
the temporary installation. Instead of running initdb, pg_regress and tap
tests can copy that data directory. When a tap test specifies options to
initdb, the template data directory is not used. That could be relaxed for
some options, but it's not clear it's worth the effort.

There unfortunately is some duplication between pg_regress.c and Cluster.pm,
but there are no easy ways of sharing that code without introducing additional
complexity.

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/20220120021859.3zpsfqn4z7ob7afz@alap3.anarazel.de
This commit is contained in:
Andres Freund
2023-08-24 14:17:03 -07:00
parent 9625845532
commit 252dcb3239
5 changed files with 163 additions and 44 deletions

View File

@ -3070,8 +3070,10 @@ testport = 40000
test_env = environment()
temp_install_bindir = test_install_location / get_option('bindir')
test_initdb_template = meson.build_root() / 'tmp_install' / 'initdb-template'
test_env.set('PG_REGRESS', pg_regress.full_path())
test_env.set('REGRESS_SHLIB', regress_module.full_path())
test_env.set('INITDB_TEMPLATE', test_initdb_template)
# Test suites that are not safe by default but can be run if selected
# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
@ -3086,6 +3088,34 @@ if library_path_var != ''
endif
# Create (and remove old) initdb template directory. Tests use that, where
# possible, to make it cheaper to run tests.
#
# Use python to remove the old cached initdb, as we cannot rely on a working
# 'rm' binary on windows.
test('initdb_cache',
python,
args: [
'-c', '''
import shutil
import sys
import subprocess
shutil.rmtree(sys.argv[1], ignore_errors=True)
sp = subprocess.run(sys.argv[2:] + [sys.argv[1]])
sys.exit(sp.returncode)
''',
test_initdb_template,
temp_install_bindir / 'initdb',
'-A', 'trust', '-N', '--no-instructions'
],
priority: setup_tests_priority - 1,
timeout: 300,
is_parallel: false,
env: test_env,
suite: ['setup'])
###############################################################
# Test Generation