Skip to content

Commit

Permalink
Add elog(PANIC, ..); use boring names
Browse files Browse the repository at this point in the history
  • Loading branch information
bayandin committed Jul 5, 2024
1 parent fbe53db commit ce27f53
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
17 changes: 15 additions & 2 deletions pgxn/neon_test_utils/neon_test_utils--1.3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
$$;
15 changes: 13 additions & 2 deletions pgxn/neon_test_utils/neontest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions test_runner/regress/test_boom.py

This file was deleted.

23 changes: 23 additions & 0 deletions test_runner/regress/test_endpoint_crash.py
Original file line number Diff line number Diff line change
@@ -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}();")

0 comments on commit ce27f53

Please sign in to comment.