aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-10-04 17:12:25 +0900
committerMichael Paquier <michael@paquier.xyz>2023-10-04 17:12:25 +0900
commit3338a9838298c4b42e2829373f70228c4fc50652 (patch)
tree9db0998951dc883d77abf6ac1bca4c2b9b8cbec9
parentc8e318b1b8d9b699a96b96db861b362550456108 (diff)
downloadpostgresql-3338a9838298c4b42e2829373f70228c4fc50652.tar.gz
postgresql-3338a9838298c4b42e2829373f70228c4fc50652.zip
test_shm_mq: Replace WAIT_EVENT_EXTENSION with custom wait events
Two custom wait events are added here: - "TestShmMqBgWorkerStartup", when setting up a set of bgworkers in wait_for_workers_to_become_ready(). - "TestShmMqMessageQueue", when waiting for a queued message in test_shm_mq_pipelined(). Author: Masahiro Ikeda Discussion: https://postgr.es/m/197bce267fa691a0ac62c86c4ab904c4@oss.nttdata.com
-rw-r--r--src/test/modules/test_shm_mq/setup.c9
-rw-r--r--src/test/modules/test_shm_mq/test.c9
2 files changed, 16 insertions, 2 deletions
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 192e5cc2ab4..abc79352b93 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -40,6 +40,9 @@ static void wait_for_workers_to_become_ready(worker_state *wstate,
volatile test_shm_mq_header *hdr);
static bool check_worker_status(worker_state *wstate);
+/* value cached, fetched from shared memory */
+static uint32 we_bgworker_startup = 0;
+
/*
* Set up a dynamic shared memory segment and zero or more background workers
* for a test run.
@@ -278,9 +281,13 @@ wait_for_workers_to_become_ready(worker_state *wstate,
break;
}
+ /* first time, allocate or get the custom wait event */
+ if (we_bgworker_startup == 0)
+ we_bgworker_startup = WaitEventExtensionNew("TestShmMqBgWorkerStartup");
+
/* Wait to be signaled. */
(void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0,
- WAIT_EVENT_EXTENSION);
+ we_bgworker_startup);
/* Reset the latch so we don't spin. */
ResetLatch(MyLatch);
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index d9be7033502..cb52a680a52 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -28,6 +28,9 @@ PG_FUNCTION_INFO_V1(test_shm_mq_pipelined);
static void verify_message(Size origlen, char *origdata, Size newlen,
char *newdata);
+/* value cached, fetched from shared memory */
+static uint32 we_message_queue = 0;
+
/*
* Simple test of the shared memory message queue infrastructure.
*
@@ -225,6 +228,10 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
if (wait)
{
+ /* first time, allocate or get the custom wait event */
+ if (we_message_queue == 0)
+ we_message_queue = WaitEventExtensionNew("TestShmMqMessageQueue");
+
/*
* If we made no progress, wait for one of the other processes to
* which we are connected to set our latch, indicating that they
@@ -232,7 +239,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
* for us to do.
*/
(void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0,
- WAIT_EVENT_EXTENSION);
+ we_message_queue);
ResetLatch(MyLatch);
CHECK_FOR_INTERRUPTS();
}