Skip to content

Commit

Permalink
tests: fix currently protocol parametrised tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLazar committed Nov 20, 2024
1 parent dfdc720 commit 34b6387
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 21 deletions.
36 changes: 36 additions & 0 deletions test_runner/fixtures/neon_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,31 @@ def safe_psql_scalar(self, query: str, log_query: bool = True) -> Any:
return self.safe_psql(query, log_query=log_query)[0][0]


class PageserverWalReceiverProtocol(str, Enum):
VANILLA = "vanilla"
INTERPRETED = "interpreted"

@staticmethod
def to_config_key_value(proto) -> tuple[str, dict[str, Any]]:
if proto == PageserverWalReceiverProtocol.VANILLA:
return (
"wal_receiver_protocol",
{
"type": "vanilla",
},
)
elif proto == PageserverWalReceiverProtocol.INTERPRETED:
return (
"wal_receiver_protocol",
{
"type": "interpreted",
"args": {"format": "protobuf", "compression": {"zstd": {"level": 1}}},
},
)
else:
raise ValueError(f"Unknown protocol type: {proto}")


class NeonEnvBuilder:
"""
Builder object to create a Neon runtime environment
Expand Down Expand Up @@ -359,6 +384,7 @@ def __init__(
safekeeper_extra_opts: Optional[list[str]] = None,
storage_controller_port_override: Optional[int] = None,
pageserver_virtual_file_io_mode: Optional[str] = None,
pageserver_wal_receiver_protocol: Optional[PageserverWalReceiverProtocol] = None,
):
self.repo_dir = repo_dir
self.rust_log_override = rust_log_override
Expand Down Expand Up @@ -412,6 +438,8 @@ def __init__(

self.pageserver_virtual_file_io_mode = pageserver_virtual_file_io_mode

self.pageserver_wal_receiver_protocol = pageserver_wal_receiver_protocol

assert test_name.startswith(
"test_"
), "Unexpectedly instantiated from outside a test function"
Expand Down Expand Up @@ -1026,6 +1054,7 @@ def __init__(self, config: NeonEnvBuilder):

self.pageserver_virtual_file_io_engine = config.pageserver_virtual_file_io_engine
self.pageserver_virtual_file_io_mode = config.pageserver_virtual_file_io_mode
self.pageserver_wal_receiver_protocol = config.pageserver_wal_receiver_protocol

# Create the neon_local's `NeonLocalInitConf`
cfg: dict[str, Any] = {
Expand Down Expand Up @@ -1095,6 +1124,13 @@ def __init__(self, config: NeonEnvBuilder):
if self.pageserver_virtual_file_io_mode is not None:
ps_cfg["virtual_file_io_mode"] = self.pageserver_virtual_file_io_mode

if self.pageserver_wal_receiver_protocol is not None:
key, value = PageserverWalReceiverProtocol.to_config_key_value(
self.pageserver_wal_receiver_protocol
)
if key not in ps_cfg:
ps_cfg[key] = value

# Create a corresponding NeonPageserver object
self.pageservers.append(
NeonPageserver(self, ps_id, port=pageserver_port, az_id=ps_cfg["availability_zone"])
Expand Down
16 changes: 12 additions & 4 deletions test_runner/regress/test_compaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from fixtures.log_helper import log
from fixtures.neon_fixtures import (
NeonEnvBuilder,
PageserverWalReceiverProtocol,
generate_uploads_and_deletions,
)
from fixtures.pageserver.http import PageserverApiException
Expand All @@ -32,8 +33,13 @@


@skip_in_debug_build("only run with release build")
@pytest.mark.parametrize("wal_receiver_protocol", ["vanilla", "interpreted"])
def test_pageserver_compaction_smoke(neon_env_builder: NeonEnvBuilder, wal_receiver_protocol: str):
@pytest.mark.parametrize(
"wal_receiver_protocol",
[PageserverWalReceiverProtocol.VANILLA, PageserverWalReceiverProtocol.INTERPRETED],
)
def test_pageserver_compaction_smoke(
neon_env_builder: NeonEnvBuilder, wal_receiver_protocol: PageserverWalReceiverProtocol
):
"""
This is a smoke test that compaction kicks in. The workload repeatedly churns
a small number of rows and manually instructs the pageserver to run compaction
Expand All @@ -42,10 +48,12 @@ def test_pageserver_compaction_smoke(neon_env_builder: NeonEnvBuilder, wal_recei
observed bounds.
"""

neon_env_builder.pageserver_wal_receiver_protocol = wal_receiver_protocol

# Effectively disable the page cache to rely only on image layers
# to shorten reads.
neon_env_builder.pageserver_config_override = f"""
page_cache_size=10; wal_receiver_protocol='{wal_receiver_protocol}'
neon_env_builder.pageserver_config_override = """
page_cache_size=10
"""

env = neon_env_builder.init_start(initial_tenant_conf=AGGRESIVE_COMPACTION_TENANT_CONF)
Expand Down
15 changes: 9 additions & 6 deletions test_runner/regress/test_crafted_wal_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from fixtures.log_helper import log
from fixtures.neon_cli import WalCraft
from fixtures.neon_fixtures import NeonEnvBuilder
from fixtures.neon_fixtures import NeonEnvBuilder, PageserverWalReceiverProtocol

# Restart nodes with WAL end having specially crafted shape, like last record
# crossing segment boundary, to test decoding issues.
Expand All @@ -19,13 +19,16 @@
"wal_record_crossing_segment_followed_by_small_one",
],
)
@pytest.mark.parametrize("wal_receiver_protocol", ["vanilla", "interpreted"])
@pytest.mark.parametrize(
"wal_receiver_protocol",
[PageserverWalReceiverProtocol.VANILLA, PageserverWalReceiverProtocol.INTERPRETED],
)
def test_crafted_wal_end(
neon_env_builder: NeonEnvBuilder, wal_type: str, wal_receiver_protocol: str
neon_env_builder: NeonEnvBuilder,
wal_type: str,
wal_receiver_protocol: PageserverWalReceiverProtocol,
):
neon_env_builder.pageserver_config_override = (
f"wal_receiver_protocol = '{wal_receiver_protocol}'"
)
neon_env_builder.pageserver_wal_receiver_protocol = wal_receiver_protocol

env = neon_env_builder.init_start()
env.create_branch("test_crafted_wal_end")
Expand Down
15 changes: 10 additions & 5 deletions test_runner/regress/test_subxacts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from __future__ import annotations

import pytest
from fixtures.neon_fixtures import NeonEnvBuilder, check_restored_datadir_content
from fixtures.neon_fixtures import (
NeonEnvBuilder,
PageserverWalReceiverProtocol,
check_restored_datadir_content,
)


# Test subtransactions
Expand All @@ -10,11 +14,12 @@
# maintained in the pageserver, so subtransactions are not very exciting for
# Neon. They are included in the commit record though and updated in the
# CLOG.
@pytest.mark.parametrize("wal_receiver_protocol", ["vanilla", "interpreted"])
@pytest.mark.parametrize(
"wal_receiver_protocol",
[PageserverWalReceiverProtocol.VANILLA, PageserverWalReceiverProtocol.INTERPRETED],
)
def test_subxacts(neon_env_builder: NeonEnvBuilder, test_output_dir, wal_receiver_protocol):
neon_env_builder.pageserver_config_override = (
f"wal_receiver_protocol = '{wal_receiver_protocol}'"
)
neon_env_builder.pageserver_wal_receiver_protocol = wal_receiver_protocol

env = neon_env_builder.init_start()
endpoint = env.endpoints.create_start("main")
Expand Down
21 changes: 15 additions & 6 deletions test_runner/regress/test_wal_acceptor_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
import toml
from fixtures.common_types import Lsn, TenantId, TimelineId
from fixtures.log_helper import getLogger
from fixtures.neon_fixtures import Endpoint, NeonEnv, NeonEnvBuilder, Safekeeper
from fixtures.neon_fixtures import (
Endpoint,
NeonEnv,
NeonEnvBuilder,
PageserverWalReceiverProtocol,
Safekeeper,
)
from fixtures.remote_storage import RemoteStorageKind
from fixtures.utils import skip_in_debug_build

Expand Down Expand Up @@ -627,12 +633,15 @@ async def run_segment_init_failure(env: NeonEnv):
# Test (injected) failure during WAL segment init.
# https://github.com/neondatabase/neon/issues/6401
# https://github.com/neondatabase/neon/issues/6402
@pytest.mark.parametrize("wal_receiver_protocol", ["vanilla", "interpreted"])
def test_segment_init_failure(neon_env_builder: NeonEnvBuilder, wal_receiver_protocol: str):
@pytest.mark.parametrize(
"wal_receiver_protocol",
[PageserverWalReceiverProtocol.VANILLA, PageserverWalReceiverProtocol.INTERPRETED],
)
def test_segment_init_failure(
neon_env_builder: NeonEnvBuilder, wal_receiver_protocol: PageserverWalReceiverProtocol
):
neon_env_builder.num_safekeepers = 1
neon_env_builder.pageserver_config_override = (
f"wal_receiver_protocol = '{wal_receiver_protocol}'"
)
neon_env_builder.pageserver_wal_receiver_protocol = wal_receiver_protocol
env = neon_env_builder.init_start()

asyncio.run(run_segment_init_failure(env))
Expand Down

0 comments on commit 34b6387

Please sign in to comment.