-
Notifications
You must be signed in to change notification settings - Fork 0
test: add basic correctness test #51
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,71 @@ | ||
| import asyncio | ||
| import sys | ||
|
|
||
| import pytest | ||
|
|
||
| from s2_sdk import Batching, ReadLimit, Record, Retry, S2Stream, SeqNum | ||
|
|
||
| TOTAL_RECORDS = 1024 | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def retry() -> Retry: | ||
| return Retry(max_attempts=sys.maxsize) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def basin_prefix() -> str: | ||
| return "python-correctness" | ||
|
|
||
|
|
||
| @pytest.mark.correctness | ||
| @pytest.mark.asyncio | ||
| async def test_concurrent_producer_and_consumer_remain_gapless(stream: S2Stream): | ||
| async def read_records() -> None: | ||
| highest_contiguous_index = -1 | ||
| last_seq_num: int | None = None | ||
| observed_records = 0 | ||
|
|
||
| async for batch in stream.read_session( | ||
| start=SeqNum(0), limit=ReadLimit(count=TOTAL_RECORDS), wait=60 | ||
| ): | ||
| for record in batch.records: | ||
| assert observed_records < TOTAL_RECORDS | ||
|
|
||
| seq_num = record.seq_num | ||
| if last_seq_num is None: | ||
| assert seq_num == 0 | ||
| else: | ||
| assert seq_num == last_seq_num + 1 | ||
| last_seq_num = seq_num | ||
|
|
||
| body = record.body.decode() | ||
| index = int(body) | ||
| assert 0 <= index < TOTAL_RECORDS | ||
| assert index <= highest_contiguous_index + 1 | ||
|
|
||
| if index == highest_contiguous_index + 1: | ||
| highest_contiguous_index = index | ||
| observed_records += 1 | ||
|
|
||
| assert highest_contiguous_index == TOTAL_RECORDS - 1 | ||
| assert last_seq_num == TOTAL_RECORDS - 1 | ||
| assert observed_records == TOTAL_RECORDS | ||
|
|
||
| async def append_records() -> None: | ||
| async with stream.producer(batching=Batching(max_records=16)) as producer: | ||
| tickets = [] | ||
| for i in range(TOTAL_RECORDS): | ||
| ticket = await producer.submit(Record(body=str(i).encode())) | ||
| tickets.append(ticket) | ||
|
|
||
| for ticket in tickets: | ||
| ack = await ticket | ||
| assert ack.seq_num >= 0 | ||
|
|
||
| async with asyncio.TaskGroup() as task_group: | ||
| task_group.create_task(read_records()) | ||
| task_group.create_task(append_records()) | ||
|
|
||
| tail = await stream.check_tail() | ||
| assert tail.seq_num == TOTAL_RECORDS | ||
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.
Uh oh!
There was an error while loading. Please reload this page.