-
Notifications
You must be signed in to change notification settings - Fork 13
Add ReuseServerTestCase for class-scoped server reuse #13
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
base: unstable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """ | ||
| Demonstrates ReuseServerTestCase usage. | ||
|
|
||
| All tests in this class share ONE server. Between each test, FLUSHALL + CONFIG | ||
| RESETSTAT run automatically to give each test a clean slate without the cost of | ||
| restarting the server. | ||
| """ | ||
|
|
||
| import pytest | ||
| from conftest import resource_port_tracker | ||
| from valkey_test_case import ReuseServerTestCase | ||
|
|
||
|
|
||
| class TestReuseServer(ReuseServerTestCase): | ||
| """Verifies that server reuse works and tests are isolated.""" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lack of setup_test to call create_server() after redesigning the ReuseServerTestCase in the 2nd commit
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're correct. After the redesign of the server reuse, the server is only created when |
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def setup_test(self, setup): | ||
| self.server, self.client = self.create_server(testdir=self.testdir) | ||
|
|
||
| def test_write_and_read(self): | ||
| """Basic write/read on the shared server.""" | ||
| self.client.set("greeting", "hello") | ||
| assert self.client.get("greeting") == b"hello" | ||
|
|
||
| def test_isolation_from_previous(self): | ||
| """Proves FLUSHALL cleaned up the previous test's data.""" | ||
| result = self.client.get("greeting") | ||
| assert result is None, "Key from previous test should not exist" | ||
|
|
||
| def test_server_still_alive(self): | ||
| """Proves the server survived across tests (no restart).""" | ||
| assert self.client.ping() is True | ||
|
|
||
| def test_multiple_keys(self): | ||
| """Write multiple keys, verify they all exist within this test.""" | ||
| for i in range(10): | ||
| self.client.set(f"key:{i}", f"value:{i}") | ||
| assert self.client.dbsize() == 10 | ||
|
|
||
| def test_previous_keys_gone(self): | ||
| """Proves the 10 keys from the previous test were flushed.""" | ||
| assert self.client.dbsize() == 0 | ||
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.
Is there any benefit to not require
testdir?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.
Added a fallback: if
testdirisn't passed, it defaults toself.testdir(same approach as server_path). This way None never reaches the parent, and modules that already passtestdir=self.testdirstill work the same.