sub launch_bgworker
{
my ($node, $database, $testcase, $interruptible) = @_;
- my $offset = -s $node->logfile;
# Launch a background worker on the given database.
my $pid = $node->safe_psql(
SELECT worker_spi_launch($testcase, '$database'::regdatabase, 0, '{}', $interruptible);
));
- # Check that the bgworker is initialized.
- $node->wait_for_log(
- qr/LOG: .*worker_spi dynamic worker $testcase initialized with .*\..*/,
- $offset);
- my $result = $node->safe_psql('postgres',
- "SELECT count(*) > 0 FROM pg_stat_activity WHERE pid = $pid;");
- is($result, 't', "dynamic bgworker $testcase launched");
+ # Check that the bgworker is initialized and napping.
+ my $result =
+ $node->poll_query_until('postgres',
+ qq[SELECT wait_event FROM pg_stat_activity WHERE pid = $pid;],
+ qq[WorkerSpiMain]);
+ is($result, 1, "dynamic bgworker $testcase launched");
return $pid;
}
my $node = PostgreSQL::Test::Cluster->new('mynode');
$node->init;
+# The naptime is large enough to give some room on slow machines, so as
+# the spawned workers have the time to process the interrupt requests sent
+# by the database commands.
$node->append_conf(
"postgresql.conf", qq(
autovacuum = off
debug_parallel_query = off
log_min_messages = debug1
+worker_spi.naptime = 600
));
$node->start;