Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELECT 馃挘(); #8270

Merged
merged 5 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pgxn/neon_test_utils/neon_test_utils--1.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ CREATE FUNCTION neon_xlogflush(lsn pg_lsn DEFAULT NULL)
RETURNS VOID
AS 'MODULE_PATHNAME', 'neon_xlogflush'
LANGUAGE C PARALLEL UNSAFE;

CREATE FUNCTION 馃挘()
RETURNS VOID
AS 'MODULE_PATHNAME', 'boom'
LANGUAGE C PARALLEL UNSAFE;
12 changes: 12 additions & 0 deletions pgxn/neon_test_utils/neontest.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ 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);

/*
* Linkage to functions in neon module.
Expand Down Expand Up @@ -489,3 +490,14 @@ neon_xlogflush(PG_FUNCTION_ARGS)
XLogFlush(lsn);
PG_RETURN_VOID();
}

/*
* Function to trigger a segfault.
*/
Datum
boom(PG_FUNCTION_ARGS)
{
int *ptr = NULL;
*ptr = 42;
PG_RETURN_VOID();
}
18 changes: 14 additions & 4 deletions test_runner/fixtures/neon_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,8 @@ def __exit__(
# if the test threw an exception, don't check for errors
# as a failing assertion would cause the cleanup below to fail
ps_assert_metric_no_errors=(exc_type is None),
# do not fail on endpoint errors to allow the rest of cleanup to proceed
fail_on_endpoint_errors=False,
)
cleanup_error = None

Expand Down Expand Up @@ -1214,11 +1216,11 @@ def start(self, timeout_in_seconds: Optional[int] = None):
for f in futs:
f.result()

def stop(self, immediate=False, ps_assert_metric_no_errors=False):
def stop(self, immediate=False, ps_assert_metric_no_errors=False, fail_on_endpoint_errors=True):
"""
After this method returns, there should be no child processes running.
"""
self.endpoints.stop_all()
self.endpoints.stop_all(fail_on_endpoint_errors)

# Stop storage controller before pageservers: we don't want it to spuriously
# detect a pageserver "failure" during test teardown
Expand Down Expand Up @@ -3899,9 +3901,17 @@ def create(
pageserver_id=pageserver_id,
)

def stop_all(self) -> "EndpointFactory":
def stop_all(self, fail_on_error=True) -> "EndpointFactory":
exception = None
for ep in self.endpoints:
ep.stop()
try:
ep.stop()
except Exception as e:
log.error(f"Failed to stop endpoint {ep.endpoint_id}: {e}")
exception = e

if fail_on_error and exception is not None:
raise exception

return self

Expand Down
15 changes: 15 additions & 0 deletions test_runner/regress/test_boom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 馃挘();")
Loading