Commit
…wn_postgres -- Start postgreSQL instance directly in tests openQA tests like `prove -l t/basic.t` already include a line `OpenQA::Test::Database->new->create;` but this still needs a database process to be present. This is detected and flagged as an error accordingly but we could make the tests themselves more convenient and less reliant on the Makefile by spawning a postgresql process itself within tests if not already running. Related progress issue: https://progress.opensuse.org/issues/102524
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,27 @@ use Try::Tiny; | |
|
||
has fixture_path => 't/fixtures'; | ||
|
||
plan skip_all => 'set TEST_PG to e.g. "DBI:Pg:dbname=test" to enable this test' unless $ENV{TEST_PG}; | ||
plan skip_all => 'set TEST_PG to e.g. "DBI:Pg:dbname=test" to enable this test' if $ENV{USE_EXTERNAL_PG} && !$ENV{TEST_PG}; | ||
|
||
sub generate_schema_name { | ||
return 'tmp_' . random_string(); | ||
} | ||
|
||
sub spawn_postgres { | ||
$ENV{TEST_PG_PATH} //= '/dev/shm/tpg'; | ||
# this times out in `prove -l -v t/03-auth.t` and I don't see any output. | ||
# Maybe it's better to use IPC::Run and show the output unbuffered or | ||
# something | ||
my $out = qx{test -d $ENV{TEST_PG_PATH} && (pg_ctl -D $ENV{TEST_PG_PATH} -s status >&/dev/null || pg_ctl -D $ENV{TEST_PG_PATH} -s start) || ./t/test_postgresql $ENV{TEST_PG_PATH}}; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
okurz
Author
Member
|
||
diag $out; | ||
$ENV{TEST_PG} = "DBI:Pg:dbname=openqa_test;host=$ENV{TEST_PG_PATH}"; | ||
} | ||
|
||
sub create { | ||
my ($self, %options) = @_; | ||
|
||
spawn_postgres; | ||
|
||
# create new database connection | ||
my $schema = OpenQA::Schema::connect_db(mode => 'test', deploy => 0); | ||
|
||
|
@@ -52,6 +64,10 @@ sub create { | |
return $schema; | ||
} | ||
|
||
END { | ||
qx{pg_ctl -D $ENV{TEST_PG_PATH} stop} unless $ENV{USE_EXTERNAL_PG} || $ENV{KEEP_DB}; | ||
} | ||
|
||
sub insert_fixtures { | ||
my ($self, $schema, $fixtures_glob) = @_; | ||
|
||
|
I'd use separate invocations here rather than chaining commands in the same shell