Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit320c311

Browse files
committed
worker_spi: Switch to TAP tests
This commit moves worker_spi to use TAP tests. sql/worker_spi.sql isgone, replaced by an equivalent set of queries in a TAP script, withoutworker_spi loaded in shared_preload_libraries:- One query to launch a worker dynamically, relying now on "postgres" asthe default database to connect to.- Two wait queries with poll_query_until(), one to wait for the workerschema to be initialized and a second to wait for a tuple processed bythe worker.- Server reload to accelerate the main loop of the spawned worker.More coverage is added for workers registered when the library is loadedwith shared_preload_libraries, while on it, checking that these areconnecting to the database set in the GUC worker_spi.database.A local run of these test is showing that TAP is slightly faster thanthe original, while providing more coverage (3.7s vs 4.4s). There wasalso some discussions about keeping the SQL tests, but this wouldrequire initializing twice a cluster, increasing the runtime of thetests up to 5.6s here.These tests will be expanded more in an upcoming patch aimed at addingsupport for custom wait events for the Extension class, still underdiscussion, to check the new in-core APIs with and without a library setin shared_preload_libraries.Bharath has written the part where shared_preload_libraries is used,while I have migrated the existing SQL tests to TAP.Author: Bharath Rupireddy, Michael PaquierReviewed-by: Masahiro IkedaDiscussion:https://postgr.es/m/CALj2ACWR9ncAiDF73unqdJF1dmsA2R0efGXX2624X+YVxcAVWg@mail.gmail.com
1 parentb635ac0 commit320c311

File tree

7 files changed

+84
-102
lines changed

7 files changed

+84
-102
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
# Generated subdirectories
2-
/log/
3-
/results/
42
/tmp_check/

‎src/test/modules/worker_spi/Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ EXTENSION = worker_spi
66
DATA = worker_spi--1.0.sql
77
PGFILEDESC = "worker_spi - background worker example"
88

9-
REGRESS = worker_spi
10-
11-
# enable our module in shared_preload_libraries for dynamic bgworkers
12-
REGRESS_OPTS = --temp-config$(top_srcdir)/src/test/modules/worker_spi/dynamic.conf
13-
14-
# Disable installcheck to ensure we cover dynamic bgworkers.
15-
NO_INSTALLCHECK = 1
9+
TAP_TESTS = 1
1610

1711
ifdefUSE_PGXS
1812
PG_CONFIG = pg_config

‎src/test/modules/worker_spi/dynamic.conf

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎src/test/modules/worker_spi/expected/worker_spi.out

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎src/test/modules/worker_spi/meson.build

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ tests += {
2525
'name':'worker_spi',
2626
'sd':meson.current_source_dir(),
2727
'bd':meson.current_build_dir(),
28-
'regress': {
29-
'sql': [
30-
'worker_spi',
28+
'tap': {
29+
'tests': [
30+
't/001_worker_spi.pl',
3131
],
32-
'dbname':'contrib_regression',
33-
'regress_args': ['--temp-config',files('dynamic.conf')],
34-
'runningcheck':false,
3532
},
3633
}

‎src/test/modules/worker_spi/sql/worker_spi.sql

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright (c) 2023, PostgreSQL Global Development Group
2+
3+
# Test worker_spi module.
4+
5+
use strict;
6+
use warnings;
7+
use PostgreSQL::Test::Cluster;
8+
use PostgreSQL::Test::Utils;
9+
use Test::More;
10+
11+
my$node = PostgreSQL::Test::Cluster->new('mynode');
12+
$node->init;
13+
$node->start;
14+
15+
note"testing dynamic bgworkers";
16+
17+
$node->safe_psql('postgres','CREATE EXTENSION worker_spi;');
18+
19+
# Launch one dynamic worker, then wait for its initialization to complete.
20+
# This consists in making sure that a table name "counted" is created
21+
# on a new schema whose name includes the index defined in input argument
22+
# of worker_spi_launch().
23+
# By default, dynamic bgworkers connect to the "postgres" database.
24+
my$result =
25+
$node->safe_psql('postgres','SELECT worker_spi_launch(4) IS NOT NULL;');
26+
is($result,'t',"dynamic bgworker launched");
27+
$node->poll_query_until(
28+
'postgres',
29+
qq[SELECT count(*) > 0 FROM information_schema.tables
30+
WHERE table_schema = 'schema4' AND table_name = 'counted';]);
31+
$node->safe_psql('postgres',
32+
"INSERT INTO schema4.counted VALUES ('total', 0), ('delta', 1);");
33+
# Issue a SIGHUP on the node to force the worker to loop once, accelerating
34+
# this test.
35+
$node->reload;
36+
# Wait until the worker has processed the tuple that has just been inserted.
37+
$node->poll_query_until('postgres',
38+
qq[SELECT count(*) FROM schema4.counted WHERE type = 'delta';],'0');
39+
$result =$node->safe_psql('postgres','SELECT * FROM schema4.counted;');
40+
is($result,qq(total|1),'dynamic bgworker correctly consumed tuple data');
41+
42+
note"testing bgworkers loaded with shared_preload_libraries";
43+
44+
# Create the database first so as the workers can connect to it when
45+
# the library is loaded.
46+
$node->safe_psql('postgres',q(CREATE DATABASE mydb;));
47+
$node->safe_psql('mydb','CREATE EXTENSION worker_spi;');
48+
49+
# Now load the module as a shared library.
50+
$node->append_conf(
51+
'postgresql.conf',q{
52+
shared_preload_libraries = 'worker_spi'
53+
worker_spi.database = 'mydb'
54+
worker_spi.total_workers = 3
55+
});
56+
$node->restart;
57+
58+
# Check that bgworkers have been registered and launched.
59+
ok($node->poll_query_until(
60+
'mydb',
61+
qq[SELECT datname, count(datname) FROM pg_stat_activity
62+
WHERE backend_type = 'worker_spi' GROUP BY datname;],
63+
'mydb|3'),
64+
'bgworkers all launched'
65+
)ordie"Timed out while waiting for bgworkers to be launched";
66+
67+
# Ask worker_spi to launch dynamic bgworkers with the library loaded, then
68+
# check their existence.
69+
my$worker1_pid =$node->safe_psql('mydb','SELECT worker_spi_launch(1);');
70+
my$worker2_pid =$node->safe_psql('mydb','SELECT worker_spi_launch(2);');
71+
ok($node->poll_query_until(
72+
'mydb',
73+
qq[SELECT datname, count(datname) FROM pg_stat_activity
74+
WHERE backend_type = 'worker_spi dynamic' AND
75+
pid IN ($worker1_pid,$worker2_pid) GROUP BY datname;],
76+
'mydb|2'),
77+
'dynamic bgworkers all launched'
78+
)ordie"Timed out while waiting for dynamic bgworkers to be launched";
79+
80+
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp