Fix new Object Access hooks test
authorAndrew Dunstan <andrew@dunslane.net>
Tue, 22 Mar 2022 17:27:26 +0000 (13:27 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Tue, 22 Mar 2022 17:27:26 +0000 (13:27 -0400)
Commit 90efa2f556 caused some issues with EXEC_BACKEND builds and with
force_parallel_mode = regress setups. For the first issue we no longer
test if the module has been preloaded, and in fact we don't preload it,
but simply LOAD it in the test script. For the second issue we suppress
error messages emanating from parallel workers.

Mark Dilger

Discussion: https://postgr.es/m/7f6d54a1-4024-3b6e-e3ec-26cd394aac9e@dunslane.net

src/test/modules/test_oat_hooks/Makefile
src/test/modules/test_oat_hooks/expected/test_oat_hooks.out
src/test/modules/test_oat_hooks/sql/test_oat_hooks.sql
src/test/modules/test_oat_hooks/test_oat_hooks.c
src/test/modules/test_oat_hooks/test_oat_hooks.conf [deleted file]

index d0df9c1abbf53f9aa1e0d533a063d6d39a302211..d03ef2caf17f75aa76464be63b202dc9c0ca1adf 100644 (file)
@@ -7,9 +7,6 @@ OBJS = \
 PGFILEDESC = "test_oat_hooks - example use of object access hooks"
 
 REGRESS = test_oat_hooks
-REGRESS_OPTS = --temp-config=$(top_srcdir)/src/test/modules/test_oat_hooks/test_oat_hooks.conf
-# Disabled because these tests require "shared_preload_libraries=test_oat_hooks",
-# which typical installcheck users do not have (e.g. buildfarm clients).
 NO_INSTALLCHECK = 1
 
 ifdef USE_PGXS
index 20357695801374b1810d14f9d2ae905b915ba0b3..4192a2fb49ec0e59f60e1dd65655416511db6a78 100644 (file)
@@ -2,6 +2,7 @@
 -- object_access_hook_str.  Since the auditing GUC starts out false, we miss the
 -- initial "attempting" audit message from the ProcessUtility_hook, but we
 -- should thereafter see the audit messages
+LOAD 'test_oat_hooks';
 SET test_oat_hooks.audit = true;
 NOTICE:  in object_access_hook_str: superuser attempting alter (set) [test_oat_hooks.audit]
 NOTICE:  in object_access_hook_str: superuser finished alter (set) [test_oat_hooks.audit]
index 5fb3a2f0ea4b3995fb908aa522d79b99f5fcf1d2..7c3820278249926fb76f07b82b5ee2503cecb259 100644 (file)
@@ -2,6 +2,7 @@
 -- object_access_hook_str.  Since the auditing GUC starts out false, we miss the
 -- initial "attempting" audit message from the ProcessUtility_hook, but we
 -- should thereafter see the audit messages
+LOAD 'test_oat_hooks';
 SET test_oat_hooks.audit = true;
 
 -- Create objects for use in the test
index b1709f4d63d2ac03d701b182fe73e0a4917b87be..b50567749c448e64ac83a01bc032370874945b67 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "postgres.h"
 
+#include "access/parallel.h"
 #include "catalog/dependency.h"
 #include "catalog/objectaccess.h"
 #include "catalog/pg_proc.h"
@@ -68,15 +69,6 @@ void     _PG_fini(void);
 void
 _PG_init(void)
 {
-   /*
-    * We allow to load the Object Access Type test module on single-user-mode
-    * or shared_preload_libraries settings only.
-    */
-   if (IsUnderPostmaster)
-       ereport(ERROR,
-               (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
-                errmsg("test_oat_hooks must be loaded via shared_preload_libraries")));
-
    /*
     * test_oat_hooks.deny_set_variable = (on|off)
     */
@@ -200,7 +192,7 @@ _PG_fini(void)
 static void
 emit_audit_message(const char *type, const char *hook, char *action, char *objName)
 {
-   if (REGRESS_audit)
+   if (REGRESS_audit && !IsParallelWorker())
    {
        const char *who = superuser_arg(GetUserId()) ? "superuser" : "non-superuser";
 
diff --git a/src/test/modules/test_oat_hooks/test_oat_hooks.conf b/src/test/modules/test_oat_hooks/test_oat_hooks.conf
deleted file mode 100644 (file)
index a44cbdd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-shared_preload_libraries = test_oat_hooks