Fix test_session_hooks with parallel workers
authorMichael Paquier <michael@paquier.xyz>
Tue, 1 Oct 2019 06:19:32 +0000 (15:19 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 1 Oct 2019 06:25:04 +0000 (15:25 +0900)
Several buildfarm machines have been complaining about the new module
test_session_hooks to be unstable, like crake and thorntail.  The issue
was that the module was trying to log some start and end session
activity for parallel workers, which makes little sense as they don't
support DML, so just prevent this pattern to happen in the module.

This could be reproduced by enforcing force_parallel_mode=regress, which
is the value used by some of the buildfarm members.

Discussion: https://postgr.es/m/20191001045246.GF2781@paquier.xyz

src/test/modules/test_session_hooks/test_session_hooks.c

index d047c5d219ab3d555efe3868f6432d237865845b..a90c373c69abf19bd9e2f3458822557bf67d694c 100644 (file)
@@ -13,6 +13,7 @@
  */
 #include "postgres.h"
 
+#include "access/parallel.h"
 #include "access/xact.h"
 #include "commands/dbcommands.h"
 #include "executor/spi.h"
@@ -89,6 +90,10 @@ sample_session_start_hook(void)
    if (!OidIsValid(MyDatabaseId))
        return;
 
+   /* no parallel workers */
+   if (IsParallelWorker())
+       return;
+
    register_session_hook("START");
 }
 
@@ -107,6 +112,10 @@ sample_session_end_hook(void)
    if (!OidIsValid(MyDatabaseId))
        return;
 
+   /* no parallel workers */
+   if (IsParallelWorker())
+       return;
+
    register_session_hook("END");
 }