-
Notifications
You must be signed in to change notification settings - Fork 476
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fast import: basic python test #10271
Open
NanoBjorn
wants to merge
20
commits into
main
Choose a base branch
from
22037-basic-fast-import-e2e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−3
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3a66eeb
Made fast_import testable locally (made s3 prefix optional, added sou…
NanoBjorn 131ab74
effective_io_concurrency=0 on macos
NanoBjorn 2f0a127
Create neondb database and restore into it
NanoBjorn ebe26e2
cargo fmt --all
NanoBjorn e291fb7
Fixture for fast_import binary is working
NanoBjorn 6e5a0ad
Implemented basic test of fast import
NanoBjorn 6d29785
Moved test_fast_import to test_import_pgdata
NanoBjorn 1e9707f
Added todo on full import test with pageserver
NanoBjorn a7f8b9f
poetry run ruff format .
NanoBjorn fd0acb6
poetry run ruff check --fix .
NanoBjorn 337ad52
Fixed initdb locale
NanoBjorn a80dcfa
Capture LD_LIBRARY_PATH from pytest env
NanoBjorn c09d817
review comments
NanoBjorn 4c2ee6a
added 10 min timeout on waiting loop
NanoBjorn ebc4735
postgres waiting timeout & retry as constants
NanoBjorn 14318af
Merge branch '22100-change-fastimport-db-name' into 22037-basic-fast-…
NanoBjorn ed189d7
Merge branch 'main' into 22037-basic-fast-import-e2e
NanoBjorn 047b986
Removed version limitation from fast import tests
NanoBjorn cf8654b
Revert "Removed version limitation from fast import tests"
NanoBjorn fd09d31
shorter pg_port definition
NanoBjorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ | |
"fixtures.compare_fixtures", | ||
"fixtures.slow", | ||
"fixtures.reruns", | ||
"fixtures.fast_import", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
from collections.abc import Iterator | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from fixtures.log_helper import log | ||
from fixtures.neon_cli import AbstractNeonCli | ||
from fixtures.pg_version import PgVersion | ||
|
||
|
||
class FastImport(AbstractNeonCli): | ||
COMMAND = "fast_import" | ||
cmd: subprocess.CompletedProcess[str] | None = None | ||
|
||
def __init__( | ||
self, | ||
extra_env: dict[str, str] | None, | ||
binpath: Path, | ||
pg_distrib_dir: Path, | ||
pg_version: PgVersion, | ||
workdir: Path, | ||
): | ||
if extra_env is None: | ||
env_vars = {} | ||
else: | ||
env_vars = extra_env.copy() | ||
|
||
if not (binpath / self.COMMAND).exists(): | ||
raise Exception(f"{self.COMMAND} binary not found at '{binpath}'") | ||
super().__init__(env_vars, binpath) | ||
|
||
pg_dir = pg_distrib_dir / pg_version.v_prefixed | ||
self.pg_distrib_dir = pg_distrib_dir | ||
self.pg_version = pg_version | ||
self.pg_bin = pg_dir / "bin" | ||
if not (self.pg_bin / "postgres").exists(): | ||
raise Exception(f"postgres binary was not found at '{self.pg_bin}'") | ||
self.pg_lib = pg_dir / "lib" | ||
if env_vars.get("LD_LIBRARY_PATH") is not None: | ||
self.pg_lib = Path(env_vars["LD_LIBRARY_PATH"]) | ||
elif os.getenv("LD_LIBRARY_PATH") is not None: | ||
self.pg_lib = Path(str(os.getenv("LD_LIBRARY_PATH"))) | ||
if not workdir.exists(): | ||
raise Exception(f"Working directory '{workdir}' does not exist") | ||
self.workdir = workdir | ||
|
||
def run( | ||
self, | ||
pg_port: int, | ||
source_connection_string: str | None = None, | ||
s3prefix: str | None = None, | ||
interactive: bool = False, | ||
) -> subprocess.CompletedProcess[str]: | ||
if self.cmd is not None: | ||
raise Exception("Command already executed") | ||
args = [ | ||
f"--pg-bin-dir={self.pg_bin}", | ||
f"--pg-lib-dir={self.pg_lib}", | ||
f"--pg-port={pg_port}", | ||
f"--working-directory={self.workdir}", | ||
] | ||
if source_connection_string is not None: | ||
args.append(f"--source-connection-string={source_connection_string}") | ||
if s3prefix is not None: | ||
args.append(f"--s3-prefix={s3prefix}") | ||
if interactive: | ||
args.append("--interactive") | ||
|
||
self.cmd = self.raw_cli(args) | ||
return self.cmd | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, *args): | ||
if self.workdir.exists(): | ||
shutil.rmtree(self.workdir) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def fast_import( | ||
pg_version: PgVersion, | ||
test_output_dir: Path, | ||
neon_binpath: Path, | ||
pg_distrib_dir: Path, | ||
) -> Iterator[FastImport]: | ||
workdir = Path(tempfile.mkdtemp()) | ||
with FastImport(None, neon_binpath, pg_distrib_dir, pg_version, workdir) as fi: | ||
yield fi | ||
|
||
if fi.cmd is None: | ||
return | ||
|
||
# dump stdout & stderr into test log dir | ||
with open(test_output_dir / "fast_import.stdout", "w") as f: | ||
f.write(fi.cmd.stdout) | ||
with open(test_output_dir / "fast_import.stderr", "w") as f: | ||
f.write(fi.cmd.stderr) | ||
|
||
log.info("Written logs to %s", test_output_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why is the
copy
needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra_env
is passed as dict by reference, so it seems better to freeze it this way at the moment of initializationbasically copied from
neon/test_runner/fixtures/neon_cli.py
Lines 177 to 180 in fd09d31