Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 995d400

Browse files
committed
Allow passing extra options to initdb for tests
Setting the environment variable PG_TEST_INITDB_EXTRA_OPTS passes extra options to initdb run by pg_regress or PostgreSQL::Test::Cluster's init. This can be useful for a wide variety of uses, like running all tests with checksums enabled, or with JIT enabled, or with different GUC settings, or with different locale settings. (Not all tests are going to pass with arbitrary options, but it is useful to run this against specific test suites.) Reviewed-by: Ian Lawrence Barwick <barwick@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/d4d2ad9f-1c1d-47a1-bb4d-c10a747d4f15%40eisentraut.org
1 parent 9bc1eee commit 995d400

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

doc/src/sgml/regress.sgml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,37 @@ make check LANG=C ENCODING=EUC_JP
390390
<title>Custom Server Settings</title>
391391

392392
<para>
393-
Custom server settings to use when running a regression test suite can be
393+
There are several ways to use custom server settings when running a test
394+
suite. This can be useful to enable additional logging, adjust resource
395+
limits, or enable extra run-time checks such as <xref
396+
linkend="guc-debug-discard-caches"/>. But note that not all tests can be
397+
expected to pass cleanly with arbitrary settings.
398+
</para>
399+
400+
<para>
401+
Extra options can be passed to the various <command>initdb</command>
402+
commands that are run internally during test setup using the environment
403+
variable <envar>PG_TEST_INITDB_EXTRA_OPTS</envar>. For example, to run a
404+
test with checksums enabled and a custom WAL segment size and
405+
<varname>work_mem</varname> setting, use:
406+
<screen>
407+
make check PG_TEST_INITDB_EXTRA_OPTS='-k --wal-segsize=4 -c work_mem=50MB'
408+
</screen>
409+
</para>
410+
411+
<para>
412+
For the core regression test suite and other tests driven by
413+
<command>pg_regress</command>, custom run-time server settings can also be
394414
set in the <varname>PGOPTIONS</varname> environment variable (for settings
395-
that allow this):
415+
that allow this), for example:
396416
<screen>
397417
make check PGOPTIONS="-c debug_parallel_query=regress -c work_mem=50MB"
398418
</screen>
419+
(This makes use of functionality provided by libpq; see <xref
420+
linkend="libpq-connect-options"/> for details.)
421+
</para>
422+
423+
<para>
399424
When running against a temporary installation, custom settings can also be
400425
set by supplying a pre-written <filename>postgresql.conf</filename>:
401426
<screen>
@@ -405,11 +430,6 @@ make check EXTRA_REGRESS_OPTS="--temp-config=test_postgresql.conf"
405430
</screen>
406431
</para>
407432

408-
<para>
409-
This can be useful to enable additional logging, adjust resource limits,
410-
or enable extra run-time checks such as <xref
411-
linkend="guc-debug-discard-caches"/>.
412-
</para>
413433
</sect2>
414434

415435
<sect2 id="regress-run-extra-tests">

src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ use Socket;
114114
use Test::More;
115115
use PostgreSQL::Test::Utils ();
116116
use PostgreSQL::Test::BackgroundPsql ();
117+
use Text::ParseWords qw(shellwords);
117118
use Time::HiRes qw(usleep);
118119
use Scalar::Util qw(blessed);
119120

@@ -519,6 +520,12 @@ sub init
519520
$params{allows_streaming} = 0 unless defined $params{allows_streaming};
520521
$params{has_archiving} = 0 unless defined $params{has_archiving};
521522

523+
my $initdb_extra_opts_env = $ENV{PG_TEST_INITDB_EXTRA_OPTS};
524+
if (defined $initdb_extra_opts_env)
525+
{
526+
push @{ $params{extra} }, shellwords($initdb_extra_opts_env);
527+
}
528+
522529
mkdir $self->backup_dir;
523530
mkdir $self->archive_dir;
524531

src/test/regress/pg_regress.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,7 @@ regression_main(int argc, char *argv[],
23062306
const char *keywords[4];
23072307
const char *values[4];
23082308
PGPing rv;
2309+
const char *initdb_extra_opts_env;
23092310

23102311
/*
23112312
* Prepare the temp instance
@@ -2327,6 +2328,8 @@ regression_main(int argc, char *argv[],
23272328
if (!directory_exists(buf))
23282329
make_directory(buf);
23292330

2331+
initdb_extra_opts_env = getenv("PG_TEST_INITDB_EXTRA_OPTS");
2332+
23302333
initStringInfo(&cmd);
23312334

23322335
/*
@@ -2339,7 +2342,7 @@ regression_main(int argc, char *argv[],
23392342
* duplicate it until we require perl at build time.
23402343
*/
23412344
initdb_template_dir = getenv("INITDB_TEMPLATE");
2342-
if (initdb_template_dir == NULL || nolocale || debug)
2345+
if (initdb_template_dir == NULL || nolocale || debug || initdb_extra_opts_env)
23432346
{
23442347
note("initializing database system by running initdb");
23452348

@@ -2352,6 +2355,8 @@ regression_main(int argc, char *argv[],
23522355
appendStringInfoString(&cmd, " --debug");
23532356
if (nolocale)
23542357
appendStringInfoString(&cmd, " --no-locale");
2358+
if (initdb_extra_opts_env)
2359+
appendStringInfo(&cmd, " %s", initdb_extra_opts_env);
23552360
appendStringInfo(&cmd, " > \"%s/log/initdb.log\" 2>&1", outputdir);
23562361
fflush(NULL);
23572362
if (system(cmd.data))

0 commit comments

Comments
 (0)