Skip to content

Migrate pynessie testing to testcontainers - #8

Merged
snazy merged 7 commits into
projectnessie:mainfrom
snazy:testcontainers
Jul 7, 2023
Merged

snazy merged 7 commits into
projectnessie:mainfrom
snazy:testcontainers

Conversation

@snazy

@snazy snazy commented Jul 5, 2023 •

Copy link
Copy Markdown
Member

Also adopt tests to (not so) recent changes:

  • require common ancestor for merges
  • remove expected content code (was required for global state)

@snazy
snazy marked this pull request as draft July 5, 2023 21:37
@snazy
snazy force-pushed the testcontainers branch 6 times, most recently from 1b06813 to b65a7e1 Compare July 6, 2023 09:32
Also adopt tests to (not so) recent changes:
* require common ancestor for merges
* remove expected content code (was required for global state)
@snazy
snazy force-pushed the testcontainers branch from b65a7e1 to da7bc5d Compare July 6, 2023 09:59
@snazy
snazy requested a review from XN137 July 6, 2023 09:59
@snazy
snazy marked this pull request as ready for review July 6, 2023 09:59
XN137
XN137 previously approved these changes Jul 7, 2023

@XN137 XN137 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

some minor questions/suggestions

the assert len(logs) == 2 change seems the most problematic

Comment thread pytest.ini Outdated
@@ -0,0 +1,3 @@
[pytest]
markers =
nessie: Test run against a Nessie container

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: localserver, nessieserver or the like? just nessie seems confusing since every test is about (py)nessie

Comment thread tests/test_nessie_cli.py
assert_that(logs[0]["message"]).starts_with("Merged dev at ")
logs = simplejson.loads(execute_cli_command(["--json", "log", "dev"]))
assert len(logs) == 1
assert_that(logs).is_length(2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: pytest has smart asserts that provide full context on failure:

https://docs.pytest.org/en/6.2.x/assert.html

so personally dont see necessity for assert_that usage tbh

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL ;)

Comment thread tests/test_nessie_cli.py
main_hash = ref_hash("main")

merge_output = execute_cli_command(["merge", "dev", "-c", main_hash])
assert_that(merge_output).is_equal_to("Merge succeeded but legacy server did not respond with additional details.\n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we remove the test, should we also remove the code around it?
if we keep the code, would it be worth to add a mechanism to run this specific test against an older docker image?

Comment thread tests/test_nessie_cli.py
assert len(merge_response.source_commits) == 1
assert len(merge_response.details) == 1
assert_that(merge_response.details[0].source_commits[0]).is_equal_to(dev_hash)
assert_that(merge_response.details).is_length(1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering:
why can we longer assert dev_hash here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source_commits + target_commits are no longer populated (removed in v2)

logs = simplejson.loads(execute_cli_command(["--json", "log", branch]))

assert len(logs) == 1
assert len(logs) == 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesnt this change now violate the comment 3 lines above i.e. "no commit to happen"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea - the comment's wrong. Removed

Comment thread tests/test_nessie_cli_error.py Outdated

@pytest.mark.vcr(record_mode="none")
@pytest.mark.nessie
@pytest.mark.skip("Test is no longer valid?")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can no longer inject error responses like this, then we might want to remove the tests instead of skipping

Comment thread tests/conftest.py
def pytest_runtest_setup(item: pytest.Item) -> None:
"""Starts a Nessie container, if needed."""
if nessie_test_config.nessie_container is None and item.get_closest_marker("nessie") is not None:
nessie_test_config.nessie_container = NessieContainer(image=NessieContainer.DEFAULT_TEST_IMAGE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is DEFAULT_TEST_IMAGE the latest "snapshot release" of the nessie image?

because DEFAULT_IMAGE is the latest official release (which we dont use in these tests now it seems).

i am wondering whether this may cause issues in the following cases:

  • snapshot is broken for some reason (suddenly pynessie PRs cant pass CI)
  • snapshot has an intentional breaking change (suddenly pynessie PRs cant pass CI even though they might be unrelated)

so just thinking out loud: maybe PR CI should run against a known good image version and on main branch we have scheduled CI run against unstable

but we can also figure out the issues once they actually happen

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about this again:

it may also be a question about compatibility guarantees i.e. what pynessie versions are working with what nessie server versions?
if we have some backwards compatibility guarantees we might want to run against those versions in CI.

previously both were released at the same time (but potentially broken due to VCR stuff not getting updated) but now with a separate repos (and versions?) it may be even less clear

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was actually the 2nd point: identify breaking changes w/ Nessie snapshot releases.

I was quite surprised how much stuff was actually no longer working - were just/mostly tests, but still.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, we'd need CI against multiple release incl "latest main". But that can be done later, WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes later is fine

Comment thread tests/conftest.py Outdated

def pytest_runtest_teardown(item: pytest.Item, nextitem: Optional[pytest.Item]) -> None:
"""Stops the Nessie container, if one was started."""
if item.get_closest_marker("nessie") is not None and nessie_test_config.nessie_container is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the is not None is often unnecessarily verbose and can be omited here for example

since we dont have 0 or the empty string here ever

Comment thread tests/README.md Outdated

Run the Quarkus server with `-Dnessie.server.send-stacktrace-to-client=false` (this is the default) to reduce
the size of the vcr cassettes and create less noise in updates related to REST api changes.
PyNessie uses released Nessie Docker containers to execute tests.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe mention NessieContainer class

@snazy
snazy requested a review from XN137 July 7, 2023 08:19
XN137
XN137 previously approved these changes Jul 7, 2023

@XN137 XN137 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest commits lgtm

but CI fails linting:

pynessie/commands/merge.py:18:1: F401 'json' imported but unused

feel free to merge if that is the only change required to pass CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants