Provide a better error message for misplaced dispatch options.
[pgsql.git] / src / test / modules / injection_points / sql / injection_points.sql
blobe3a481d6044928c707e8e4a238becb1bb355a621
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)
8   RETURNS void
9   AS :'regresslib'
10   LANGUAGE C STRICT;
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');
44 -- Loading
45 SELECT injection_points_cached('TestInjectionLogLoad'); -- nothing in cache
46 SELECT injection_points_load('TestInjectionLogLoad'); -- nothing
47 SELECT injection_points_attach('TestInjectionLogLoad', 'notice');
48 SELECT injection_points_load('TestInjectionLogLoad'); -- nothing happens
49 SELECT injection_points_cached('TestInjectionLogLoad'); -- runs from cache
50 SELECT injection_points_run('TestInjectionLogLoad'); -- runs from cache
51 SELECT injection_points_detach('TestInjectionLogLoad');
53 -- Runtime conditions
54 SELECT injection_points_attach('TestConditionError', 'error');
55 -- Any follow-up injection point attached will be local to this process.
56 SELECT injection_points_set_local();
57 SELECT injection_points_attach('TestConditionLocal1', 'error');
58 SELECT injection_points_attach('TestConditionLocal2', 'notice');
59 SELECT injection_points_run('TestConditionLocal1'); -- error
60 SELECT injection_points_run('TestConditionLocal2'); -- notice
62 SELECT pg_backend_pid() AS oldpid \gset
64 -- reload, local injection points should be gone.
66 -- Wait for the previous backend process to exit, ensuring that its local
67 -- injection points are cleaned up.
68 SELECT wait_pid(:'oldpid');
69 SELECT injection_points_run('TestConditionLocal1'); -- nothing
70 SELECT injection_points_run('TestConditionLocal2'); -- nothing
71 SELECT injection_points_run('TestConditionError'); -- error
72 SELECT injection_points_detach('TestConditionError');
73 -- Attaching injection points that use the same name as one defined locally
74 -- previously should work.
75 SELECT injection_points_attach('TestConditionLocal1', 'error');
76 SELECT injection_points_detach('TestConditionLocal1');
78 DROP EXTENSION injection_points;
79 DROP FUNCTION wait_pid;