Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 215
refactor: incorporate will_accept() checks into publish()#108
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
60b8912
refactor: incorporate will_accept() checks into publish()
1377eec
delete will_accept() method
4f64faa
add unit tests
1841fff
Merge branch 'master' into erase_will_accept_method
70b7cd5
add zero max messages unit test
c6944c9
Merge branch 'master' into erase_will_accept_method
pradn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -46,33 +46,3 @@ def test_len(): | ||
| assert len(batch) == 0 | ||
| batch.publish(types.PubsubMessage(data=b"foo")) | ||
| assert len(batch) == 1 | ||
| def test_will_accept(): | ||
IlyaFaer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| batch = create_batch(status=BatchStatus.ACCEPTING_MESSAGES) | ||
| message = types.PubsubMessage() | ||
| assert batch.will_accept(message) is True | ||
| def test_will_accept_oversize(): | ||
| batch = create_batch( | ||
| settings=types.BatchSettings(max_bytes=10), | ||
| status=BatchStatus.ACCEPTING_MESSAGES, | ||
| ) | ||
| message = types.PubsubMessage(data=b"abcdefghijklmnopqrstuvwxyz") | ||
| assert batch.will_accept(message) is True | ||
| def test_will_not_accept_status(): | ||
| batch = create_batch(status="talk to the hand") | ||
| message = types.PubsubMessage() | ||
| assert batch.will_accept(message) is False | ||
| def test_will_not_accept_number(): | ||
| batch = create_batch( | ||
| settings=types.BatchSettings(max_messages=-1), | ||
| status=BatchStatus.ACCEPTING_MESSAGES, | ||
| ) | ||
| message = types.PubsubMessage(data=b"abc") | ||
| assert batch.will_accept(message) is False | ||
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 |
|---|---|---|
| @@ -287,18 +287,56 @@ def test_publish_updating_batch_size(): | ||
| assert batch.size > 0 # I do not always trust protobuf. | ||
| def test_publish_not_will_accept(): | ||
IlyaFaer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_publish(): | ||
IlyaFaer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| batch = create_batch() | ||
| message = types.PubsubMessage() | ||
| future = batch.publish(message) | ||
| assert len(batch.messages) == 1 | ||
| assert batch._futures == [future] | ||
| def test_publish_max_messages_zero(): | ||
| batch = create_batch(topic="topic_foo", max_messages=0) | ||
| base_request_size = types.PublishRequest(topic="topic_foo").ByteSize() | ||
| # Publish the message. | ||
| message = types.PubsubMessage(data=b"foobarbaz") | ||
| with mock.patch.object(batch, "commit") as commit: | ||
| future = batch.publish(message) | ||
| assert future is not None | ||
| assert len(batch.messages) == 1 | ||
| assert batch._futures == [future] | ||
| commit.assert_called_once() | ||
| def test_publish_max_messages_enforced(): | ||
| batch = create_batch(topic="topic_foo", max_messages=1) | ||
| message = types.PubsubMessage(data=b"foobarbaz") | ||
| message2 = types.PubsubMessage(data=b"foobarbaz2") | ||
| future = batch.publish(message) | ||
| future2 = batch.publish(message2) | ||
| assert future is not None | ||
| assert future2 is None | ||
| assert len(batch.messages) == 1 | ||
| assert len(batch._futures) == 1 | ||
| def test_publish_max_bytes_enforced(): | ||
| batch = create_batch(topic="topic_foo", max_bytes=15) | ||
| message = types.PubsubMessage(data=b"foobarbaz") | ||
| message2 = types.PubsubMessage(data=b"foobarbaz2") | ||
| future = batch.publish(message) | ||
| future2 = batch.publish(message2) | ||
| assert future is None | ||
| assert batch.size == base_request_size | ||
| assert batch.messages == [] | ||
| assert batch._futures == [] | ||
| assert future is not None | ||
| assert future2 is None | ||
| assert len(batch.messages) == 1 | ||
| assert len(batch._futures) == 1 | ||
| def test_publish_exceed_max_messages(): | ||
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
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.