diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-07-26 15:12:21 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-07-26 15:12:21 +0300 |
commit | 20e0e7da9bc0089433c70b2b53ddf6a340ab5df3 (patch) | |
tree | a4078e7e981efe7776d4681bfa831fb61c121f47 /doc/src | |
parent | b9e5249c29354186576d8fc00609fe7eaf7c8d25 (diff) | |
download | postgresql-20e0e7da9bc0089433c70b2b53ddf6a340ab5df3.tar.gz postgresql-20e0e7da9bc0089433c70b2b53ddf6a340ab5df3.zip |
Add test for early backend startup errors
The new test tests the libpq fallback behavior on an early error,
which was fixed in the previous commit.
This adds an IS_INJECTION_POINT_ATTACHED() macro, to allow writing
injected test code alongside the normal source code. In principle, the
new test could've been implemented by an extra test module with a
callback that sets the FrontendProtocol global variable, but I think
it's more clear to have the test code right where the injection point
is, because it has pretty intimate knowledge of the surrounding
context it runs in.
Reviewed-by: Michael Paquier
Discussion: https://www.postgresql.org/message-id/CAOYmi%2Bnwvu21mJ4DYKUa98HdfM_KZJi7B1MhyXtnsyOO-PB6Ww%40mail.gmail.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/xfunc.sgml | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 7e92e898460..5b584a4f144 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -3673,6 +3673,31 @@ custom_injection_callback(const char *name, const void *private_data) </para> <para> + An alternative way to define the action to take when an injection point + is reached is to add the testing code alongside the normal source + code. This can be useful if the action e.g. depends on local variables + that are not accessible to loaded modules. The + <function>IS_INJECTION_POINT_ATTACHED</function> macro can then be used + to check if an injection point is attached, for example: +<programlisting> +#ifdef USE_INJECTION_POINTS +if (IS_INJECTION_POINT_ATTACHED("before-foobar")) +{ + /* change a local variable if injection point is attached */ + local_var = 123; + + /* also execute the callback */ + INJECTION_POINT_CACHED("before-foobar"); +} +#endif +</programlisting> + Note that the callback attached to the injection point will not be + executed by the <function>IS_INJECTION_POINT_ATTACHED</function> + macro. If you want to execute the callback, you must also call + <function>INJECTION_POINT_CACHED</function> like in the above example. + </para> + + <para> Optionally, it is possible to detach an injection point by calling: <programlisting> extern bool InjectionPointDetach(const char *name); |