Skip to content

Commit

Permalink
try to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hlinnaka committed Apr 5, 2023
1 parent 2735f1c commit 1f2946a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
12 changes: 8 additions & 4 deletions test_runner/fixtures/neon_fixtures.py
Expand Up @@ -2770,11 +2770,15 @@ def start(self) -> "Endpoint":

return self

def pg_data_dir_path(self) -> str:
"""Path to data directory"""
def endpoint_path(self) -> Path:
"""Path to endpoint directory"""
assert self.endpoint_id
path = Path("endpoints") / self.endpoint_id / "pgdata"
return os.path.join(self.env.repo_dir, path)
path = Path("endpoints") / self.endpoint_id
return self.env.repo_dir / path

def pg_data_dir_path(self) -> str:
"""Path to Postgres data directory"""
return os.path.join(self.endpoint_path(), "pgdata")

def pg_xact_dir_path(self) -> str:
"""Path to pg_xact dir"""
Expand Down
4 changes: 3 additions & 1 deletion test_runner/regress/test_branching.py
Expand Up @@ -81,7 +81,9 @@ def run_pgbench(connstr: str):

endpoints.append(env.endpoints.create_start("b{}".format(i + 1), tenant_id=tenant))

threads.append(threading.Thread(target=run_pgbench, args=(endpoints[-1],), daemon=True))
threads.append(
threading.Thread(target=run_pgbench, args=(endpoints[-1].connstr(),), daemon=True)
)
threads[-1].start()

for thread in threads:
Expand Down
45 changes: 34 additions & 11 deletions test_runner/regress/test_compatibility.py
@@ -1,3 +1,4 @@
import copy
import os
import shutil
import subprocess
Expand Down Expand Up @@ -94,6 +95,9 @@ def test_backward_compatibility(
pg_version: str,
request: FixtureRequest,
):
"""
Test that the new binaries can read old data
"""
compatibility_snapshot_dir_env = os.environ.get("COMPATIBILITY_SNAPSHOT_DIR")
assert (
compatibility_snapshot_dir_env is not None
Expand All @@ -116,6 +120,7 @@ def test_backward_compatibility(
check_neon_works(
test_output_dir / "compatibility_snapshot" / "repo",
neon_binpath,
neon_binpath,
pg_distrib_dir,
pg_version,
port_distributor,
Expand Down Expand Up @@ -143,7 +148,11 @@ def test_forward_compatibility(
port_distributor: PortDistributor,
pg_version: str,
request: FixtureRequest,
neon_binpath: Path,
):
"""
Test that the old binaries can read new data
"""
compatibility_neon_bin_env = os.environ.get("COMPATIBILITY_NEON_BIN")
assert compatibility_neon_bin_env is not None, (
"COMPATIBILITY_NEON_BIN is not set. It should be set to a path with Neon binaries "
Expand Down Expand Up @@ -178,6 +187,7 @@ def test_forward_compatibility(
check_neon_works(
test_output_dir / "compatibility_snapshot" / "repo",
compatibility_neon_bin,
neon_binpath,
compatibility_postgres_distrib_dir,
pg_version,
port_distributor,
Expand Down Expand Up @@ -218,9 +228,13 @@ def prepare_snapshot(
for logfile in repo_dir.glob("**/*.log"):
logfile.unlink()

# Remove old computes
for tenant in (repo_dir / "endpoints").glob("*"):
shutil.rmtree(tenant)
# Remove old computes in 'endpoints'. Old versions of the control plane used a directory
# called "pgdatadirs". Delete it, too.
if (repo_dir / "endpoints").exists():
shutil.rmtree(repo_dir / "endpoints")
if (repo_dir / "pgdatadirs").exists():
shutil.rmtree(repo_dir / "pgdatadirs")
os.mkdir(repo_dir / "endpoints")

# Remove wal-redo temp directory if it exists. Newer pageserver versions don't create
# them anymore, but old versions did.
Expand Down Expand Up @@ -321,7 +335,8 @@ def get_neon_version(neon_binpath: Path):

def check_neon_works(
repo_dir: Path,
neon_binpath: Path,
neon_target_binpath: Path,
neon_current_binpath: Path,
pg_distrib_dir: Path,
pg_version: str,
port_distributor: PortDistributor,
Expand All @@ -331,7 +346,7 @@ def check_neon_works(
):
snapshot_config_toml = repo_dir / "config"
snapshot_config = toml.load(snapshot_config_toml)
snapshot_config["neon_distrib_dir"] = str(neon_binpath)
snapshot_config["neon_distrib_dir"] = str(neon_target_binpath)
snapshot_config["postgres_distrib_dir"] = str(pg_distrib_dir)
with (snapshot_config_toml).open("w") as f:
toml.dump(snapshot_config, f)
Expand All @@ -342,17 +357,25 @@ def check_neon_works(
config.repo_dir = repo_dir
config.pg_version = pg_version
config.initial_tenant = snapshot_config["default_tenant_id"]
config.neon_binpath = neon_binpath
config.pg_distrib_dir = pg_distrib_dir
config.preserve_database_files = True

cli = NeonCli(config)
cli.raw_cli(["start"])
request.addfinalizer(lambda: cli.raw_cli(["stop"]))
# Use the "target" binaries to launch the storage nodes
config_target = config
config_target.neon_binpath = neon_target_binpath
cli_target = NeonCli(config_target)

# And the current binaries to launch computes
config_current = copy.copy(config)
config_current.neon_binpath = neon_current_binpath
cli_current = NeonCli(config_current)

cli_target.raw_cli(["start"])
request.addfinalizer(lambda: cli_target.raw_cli(["stop"]))

pg_port = port_distributor.get_port()
cli.endpoint_start("main", port=pg_port)
request.addfinalizer(lambda: cli.endpoint_stop("main"))
cli_current.endpoint_start("main", port=pg_port)
request.addfinalizer(lambda: cli_current.endpoint_stop("main"))

connstr = f"host=127.0.0.1 port={pg_port} user=cloud_admin dbname=postgres"
pg_bin.run(["pg_dumpall", f"--dbname={connstr}", f"--file={test_output_dir / 'dump.sql'}"])
Expand Down
3 changes: 3 additions & 0 deletions test_runner/regress/test_compute_ctl.py
Expand Up @@ -29,6 +29,9 @@ def test_sync_safekeepers_logs(neon_env_builder: NeonEnvBuilder, pg_bin: PgBin):

endpoint.stop_and_destroy()

# stop_and_destroy removes the whole endpoint directory. Recreate it.
Path(pgdata).mkdir(parents=True)

spec = (
"""
{
Expand Down

0 comments on commit 1f2946a

Please sign in to comment.