diff --git a/pgxn/neon_test_utils/neon_test_utils--1.3.sql b/pgxn/neon_test_utils/neon_test_utils--1.3.sql index b91c9dee42cc..3b8794a8cff4 100644 --- a/pgxn/neon_test_utils/neon_test_utils--1.3.sql +++ b/pgxn/neon_test_utils/neon_test_utils--1.3.sql @@ -46,7 +46,20 @@ RETURNS VOID AS 'MODULE_PATHNAME', 'neon_xlogflush' LANGUAGE C PARALLEL UNSAFE; -CREATE FUNCTION 💣() +CREATE FUNCTION trigger_panic() RETURNS VOID -AS 'MODULE_PATHNAME', 'boom' +AS 'MODULE_PATHNAME', 'trigger_panic' LANGUAGE C PARALLEL UNSAFE; + +CREATE FUNCTION trigger_segfault() +RETURNS VOID +AS 'MODULE_PATHNAME', 'trigger_segfault' +LANGUAGE C PARALLEL UNSAFE; + +-- Alias for `trigger_segfault`, just because `SELECT 💣()` looks fun +CREATE OR REPLACE FUNCTION 💣() RETURNS void +LANGUAGE plpgsql AS $$ +BEGIN + PERFORM trigger_segfault(); +END; +$$; diff --git a/pgxn/neon_test_utils/neontest.c b/pgxn/neon_test_utils/neontest.c index c0c98e241ff1..650ef7405d64 100644 --- a/pgxn/neon_test_utils/neontest.c +++ b/pgxn/neon_test_utils/neontest.c @@ -42,7 +42,8 @@ PG_FUNCTION_INFO_V1(clear_buffer_cache); PG_FUNCTION_INFO_V1(get_raw_page_at_lsn); PG_FUNCTION_INFO_V1(get_raw_page_at_lsn_ex); PG_FUNCTION_INFO_V1(neon_xlogflush); -PG_FUNCTION_INFO_V1(boom); +PG_FUNCTION_INFO_V1(trigger_panic); +PG_FUNCTION_INFO_V1(trigger_segfault); /* * Linkage to functions in neon module. @@ -491,11 +492,21 @@ neon_xlogflush(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } +/* + * Function to trigger panic. + */ +Datum +trigger_panic(PG_FUNCTION_ARGS) +{ + elog(PANIC, "neon_test_utils: panic"); + PG_RETURN_VOID(); +} + /* * Function to trigger a segfault. */ Datum -boom(PG_FUNCTION_ARGS) +trigger_segfault(PG_FUNCTION_ARGS) { int *ptr = NULL; *ptr = 42; diff --git a/test_runner/regress/test_boom.py b/test_runner/regress/test_boom.py deleted file mode 100644 index 47ddc83f0c99..000000000000 --- a/test_runner/regress/test_boom.py +++ /dev/null @@ -1,15 +0,0 @@ -import pytest -from fixtures.neon_fixtures import NeonEnvBuilder - - -def test_boom(neon_env_builder: NeonEnvBuilder): - """ - Test that calling `SELECT 💣();` (from neon_test_utils) crashes the endpoint - """ - env = neon_env_builder.init_start() - env.neon_cli.create_branch("test_💣") - endpoint = env.endpoints.create_start("test_💣") - - endpoint.safe_psql("CREATE EXTENSION neon_test_utils;") - with pytest.raises(Exception, match="This probably means the server terminated abnormally"): - endpoint.safe_psql("SELECT 💣();") diff --git a/test_runner/regress/test_endpoint_crash.py b/test_runner/regress/test_endpoint_crash.py new file mode 100644 index 000000000000..ae3dded437a0 --- /dev/null +++ b/test_runner/regress/test_endpoint_crash.py @@ -0,0 +1,23 @@ +import pytest +from fixtures.neon_fixtures import NeonEnvBuilder + + +@pytest.mark.parametrize( + "sql_func", + [ + "trigger_panic", + "trigger_segfault", + "💣", # calls `trigger_segfault` internally + ], +) +def test_endpoint_crash(neon_env_builder: NeonEnvBuilder, sql_func: str): + """ + Test that triggering crash from neon_test_utils crashes the endpoint + """ + env = neon_env_builder.init_start() + env.neon_cli.create_branch("test_endpoint_crash") + endpoint = env.endpoints.create_start("test_endpoint_crash") + + endpoint.safe_psql("CREATE EXTENSION neon_test_utils;") + with pytest.raises(Exception, match="This probably means the server terminated abnormally"): + endpoint.safe_psql(f"SELECT {sql_func}();")