From: Michael Paquier <michael@paquier.xyz>
To: Andrey M. Borodin <x4mmm@yandex-team.ru>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Subject: Re: Weird test mixup
Date: Mon, 8 Apr 2024 16:33:48 +0900
Message-ID: <ZhOd3NXAutteokGL@paquier.xyz> (raw)
In-Reply-To: <ZhNG4Io9uYOgwv3F@paquier.xyz>
References: <2387221.1710454778@sss.pgh.pa.us>
<ZfOABU4ahF2QZQ6N@paquier.xyz>
<2393552.1710458033@sss.pgh.pa.us>
<ZfP7IDs9TvrKe49x@paquier.xyz>
<e1a7ab78-1fa9-419c-b0d1-36d971bdf946@iki.fi>
<ZfTcZW1-Kh3fFLnZ@paquier.xyz>
<ZfeTLfltCTimaVbU@paquier.xyz>
<Zg9frr5iIam3fhd7@paquier.xyz>
<FB71B3B1-D68F-4508-BA95-D427792FAB2B@yandex-team.ru>
<ZhNG4Io9uYOgwv3F@paquier.xyz>
On Mon, Apr 08, 2024 at 10:22:40AM +0900, Michael Paquier wrote:
> For now I have applied 997db123c054 to make the GIN tests with
> injection points repeatable as it was an independent issue, and
> f587338dec87 to add the local function pieces.
Bharath has reported me offlist that one of the new tests has a race
condition when doing the reconnection. When the backend creating the
local points is very slow to exit, the backend created after the
reconnection may detect that a local point previously created still
exists, causing a failure. The failure can be reproduced with a sleep
in the shmem exit callback, like:
inline patch 1: src/test/modules/injection_points/injection_points.c (+2/-0 lines) download inline-1.patch--- a/src/test/modules/injection_points/injection_points.c+++ b/src/test/modules/injection_points/injection_points.c@@ -163,6 +163,8 @@ injection_points_cleanup(int code, Datum arg)
if (!injection_point_local)
return;
+ pg_usleep(1000000 * 1L);+
SpinLockAcquire(&inj_state->lock);
for (int i = 0; i < INJ_MAX_CONDITION; i++)
{
At first I was looking at a loop with a scan of pg_stat_activity, but
I've noticed that regress.so includes a wait_pid() that we can use to
make sure that a given process exits before moving on to the next
parts of a test, so I propose to just reuse that here. This requires
tweaks with --dlpath for meson and ./configure, nothing new. The CI
is clean. Patch attached.
Thoughts?
--
Michael
Patches and attachments:download all (3 files, .tar.gz)0001-Stabilize-injection-point-test.patch (text/x-diff, 4.1K) download
From 8f43807000c1f33a0238d7bbcc148a196e4134e4 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Mon, 8 Apr 2024 16:28:17 +0900
Subject: [PATCH] Stabilize injection point test
---
src/test/modules/injection_points/Makefile | 1 +
.../expected/injection_points.out | 16 ++++++++++++++++
src/test/modules/injection_points/meson.build | 1 +
.../injection_points/sql/injection_points.sql | 15 +++++++++++++++
4 files changed, 33 insertions(+)
diff --git a/src/test/modules/injection_points/Makefile b/src/test/modules/injection_points/Makefileindex 1cb395c37a..31bd787994 100644--- a/src/test/modules/injection_points/Makefile+++ b/src/test/modules/injection_points/Makefile@@ -7,6 +7,7 @@ DATA = injection_points--1.0.sql
PGFILEDESC = "injection_points - facility for injection points"
REGRESS = injection_points
+REGRESS_OPTS = --dlpath=$(top_builddir)/src/test/regress
# The injection points are cluster-wide, so disable installcheck
NO_INSTALLCHECK = 1
diff --git a/src/test/modules/injection_points/expected/injection_points.out b/src/test/modules/injection_points/expected/injection_points.outindex 3d94016ac9..d2a69b54e8 100644--- a/src/test/modules/injection_points/expected/injection_points.out+++ b/src/test/modules/injection_points/expected/injection_points.out@@ -1,4 +1,11 @@
CREATE EXTENSION injection_points;
+\getenv libdir PG_LIBDIR+\getenv dlsuffix PG_DLSUFFIX+\set regresslib :libdir '/regress' :dlsuffix+CREATE FUNCTION wait_pid(int)+ RETURNS void+ AS :'regresslib'+ LANGUAGE C STRICT;
SELECT injection_points_attach('TestInjectionBooh', 'booh');
ERROR: incorrect action "booh" for injection point creation
SELECT injection_points_attach('TestInjectionError', 'error');
@@ -156,8 +163,17 @@ NOTICE: notice triggered for injection point TestConditionLocal2
(1 row)
+select pg_backend_pid() as oldpid \gset
-- reload, local injection points should be gone.
\c
+-- Wait for the previous backend process to exit, ensuring that its local+-- injection points are cleaned up.+SELECT wait_pid(:'oldpid');+ wait_pid +----------+ +(1 row)+
SELECT injection_points_run('TestConditionLocal1'); -- nothing
injection_points_run
----------------------
diff --git a/src/test/modules/injection_points/meson.build b/src/test/modules/injection_points/meson.buildindex a29217f75f..8e1b5b4539 100644--- a/src/test/modules/injection_points/meson.build+++ b/src/test/modules/injection_points/meson.build@@ -33,6 +33,7 @@ tests += {
'sql': [
'injection_points',
],
+ 'regress_args': ['--dlpath', meson.build_root() / 'src/test/regress'],
# The injection points are cluster-wide, so disable installcheck
'runningcheck': false,
},
diff --git a/src/test/modules/injection_points/sql/injection_points.sql b/src/test/modules/injection_points/sql/injection_points.sqlindex 2aa76a542b..e18146eb8c 100644--- a/src/test/modules/injection_points/sql/injection_points.sql+++ b/src/test/modules/injection_points/sql/injection_points.sql@@ -1,5 +1,14 @@
CREATE EXTENSION injection_points;
+\getenv libdir PG_LIBDIR+\getenv dlsuffix PG_DLSUFFIX+\set regresslib :libdir '/regress' :dlsuffix++CREATE FUNCTION wait_pid(int)+ RETURNS void+ AS :'regresslib'+ LANGUAGE C STRICT;+
SELECT injection_points_attach('TestInjectionBooh', 'booh');
SELECT injection_points_attach('TestInjectionError', 'error');
SELECT injection_points_attach('TestInjectionLog', 'notice');
@@ -40,8 +49,14 @@ SELECT injection_points_attach('TestConditionLocal1', 'error');
SELECT injection_points_attach('TestConditionLocal2', 'notice');
SELECT injection_points_run('TestConditionLocal1'); -- error
SELECT injection_points_run('TestConditionLocal2'); -- notice
++select pg_backend_pid() as oldpid \gset+
-- reload, local injection points should be gone.
\c
+-- Wait for the previous backend process to exit, ensuring that its local+-- injection points are cleaned up.+SELECT wait_pid(:'oldpid');
SELECT injection_points_run('TestConditionLocal1'); -- nothing
SELECT injection_points_run('TestConditionLocal2'); -- nothing
SELECT injection_points_run('TestConditionError'); -- error
--
2.43.0
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: michael@paquier.xyz, x4mmm@yandex-team.ru, hlinnaka@iki.fi, tgl@sss.pgh.pa.us, bharath.rupireddyforpostgres@gmail.com
Subject: Re: Weird test mixup
In-Reply-To: <ZhOd3NXAutteokGL@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox