1 CREATE EXTENSION injection_points;
3 \getenv libdir PG_LIBDIR
4 \getenv dlsuffix PG_DLSUFFIX
5 \set regresslib :libdir '/regress' :dlsuffix
7 CREATE FUNCTION wait_pid(int)
12 SELECT injection_points_attach('TestInjectionBooh', 'booh');
13 SELECT injection_points_attach('TestInjectionError', 'error');
14 SELECT injection_points_attach('TestInjectionLog', 'notice');
15 SELECT injection_points_attach('TestInjectionLog2', 'notice');
17 SELECT injection_points_run('TestInjectionBooh'); -- nothing
18 SELECT injection_points_run('TestInjectionLog2'); -- notice
19 SELECT injection_points_run('TestInjectionLog'); -- notice
20 SELECT injection_points_run('TestInjectionError'); -- error
22 -- Re-load cache and run again.
24 SELECT injection_points_run('TestInjectionLog2'); -- notice
25 SELECT injection_points_run('TestInjectionLog'); -- notice
26 SELECT injection_points_run('TestInjectionError'); -- error
28 -- Remove one entry and check the remaining entries.
29 SELECT injection_points_detach('TestInjectionError'); -- ok
30 SELECT injection_points_run('TestInjectionLog'); -- notice
31 SELECT injection_points_run('TestInjectionError'); -- nothing
32 -- More entries removed, letting TestInjectionLog2 to check the same
33 -- callback used in more than one point.
34 SELECT injection_points_detach('TestInjectionLog'); -- ok
35 SELECT injection_points_run('TestInjectionLog'); -- nothing
36 SELECT injection_points_run('TestInjectionError'); -- nothing
37 SELECT injection_points_run('TestInjectionLog2'); -- notice
39 SELECT injection_points_detach('TestInjectionLog'); -- fails
41 SELECT injection_points_run('TestInjectionLog2'); -- notice
42 SELECT injection_points_detach('TestInjectionLog2');
45 SELECT injection_points_attach('TestConditionError', 'error');
46 -- Any follow-up injection point attached will be local to this process.
47 SELECT injection_points_set_local();
48 SELECT injection_points_attach('TestConditionLocal1', 'error');
49 SELECT injection_points_attach('TestConditionLocal2', 'notice');
50 SELECT injection_points_run('TestConditionLocal1'); -- error
51 SELECT injection_points_run('TestConditionLocal2'); -- notice
53 SELECT pg_backend_pid() AS oldpid \gset
55 -- reload, local injection points should be gone.
57 -- Wait for the previous backend process to exit, ensuring that its local
58 -- injection points are cleaned up.
59 SELECT wait_pid(:'oldpid');
60 SELECT injection_points_run('TestConditionLocal1'); -- nothing
61 SELECT injection_points_run('TestConditionLocal2'); -- nothing
62 SELECT injection_points_run('TestConditionError'); -- error
63 SELECT injection_points_detach('TestConditionError');
64 -- Attaching injection points that use the same name as one defined locally
65 -- previously should work.
66 SELECT injection_points_attach('TestConditionLocal1', 'error');
67 SELECT injection_points_detach('TestConditionLocal1');
69 DROP EXTENSION injection_points;
70 DROP FUNCTION wait_pid;