-
Notifications
You must be signed in to change notification settings - Fork 16
fix: shutdown event loop if publisher fails to start and set exception on result future #124
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
Show all changes
19 commits
Select commit
Hold shift + click to select a range
03951be
feat: adding ability to create subscriptions at head
hannahrogers-google 2064449
Merge branch 'master' of github.com:googleapis/python-pubsublite into…
hannahrogers-google 94d0fed
fix: lint errors
hannahrogers-google 730a278
fix: remove absl dependency
hannahrogers-google 1e508b2
Merge branch 'master' of github.com:googleapis/python-pubsublite into…
hannahrogers-google cfad1e0
fix: lint
hannahrogers-google 92609d3
Merge pull request #1 from hannahrogers-google/seek-to-head
hannahrogers-google 02694ad
feat: use default keyword args
hannahrogers-google 13a571a
Merge branch 'master' of github.com:googleapis/python-pubsublite
hannahrogers-google abf1a4f
fix: rename offset location to backlog location
hannahrogers-google c7279ad
fix: broken samples
hannahrogers-google bb03a4d
Merge branch 'master' of github.com:googleapis/python-pubsublite
hannahrogers-google 700fb7d
fix: do not crash if pubsublite distribution can not be found when ex…
hannahrogers-google bdee7eb
fix: properly shutdown event loop when failing to initialize publisher
hannahrogers-google 71b7e72
Merge branch 'master' of github.com:googleapis/python-pubsublite
hannahrogers-google df63818
fix: ensure proper shutdown on failure
hannahrogers-google cc10147
Merge branch 'master' of github.com:googleapis/python-pubsublite
hannahrogers-google 1e56434
fix: remove unused dep
hannahrogers-google 2af6cbb
fix: adding tests and requested changes
hannahrogers-google 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
Empty file.
78 changes: 78 additions & 0 deletions
78
tests/unit/pubsublite/cloudpubsub/internal/multiplexed_publisher_client_test.py
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,78 @@ | ||
| # Copyright 2020 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from asynctest.mock import MagicMock | ||
| import pytest | ||
|
|
||
| from google.cloud.pubsublite.cloudpubsub.internal.multiplexed_publisher_client import ( | ||
| MultiplexedPublisherClient, | ||
| ) | ||
| from google.cloud.pubsublite.cloudpubsub.internal.single_publisher import ( | ||
| SinglePublisher, | ||
| ) | ||
| from google.cloud.pubsublite.types import TopicPath | ||
| from google.api_core.exceptions import GoogleAPICallError | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def topic1(): | ||
| return TopicPath.parse("projects/1/locations/us-central1-a/topics/topic1") | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def topic2(): | ||
| return TopicPath.parse("projects/1/locations/us-central1-a/topics/topic2") | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def topic1_publisher(): | ||
| topic1_publisher = MagicMock(spec=SinglePublisher) | ||
| return topic1_publisher | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def topic2_publisher(): | ||
| topic2_publisher = MagicMock(spec=SinglePublisher) | ||
| return topic2_publisher | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def multiplexed_publisher(topic1, topic1_publisher, topic2_publisher): | ||
| return MultiplexedPublisherClient( | ||
| lambda topic: topic1_publisher if topic == topic1 else topic2_publisher | ||
| ) | ||
|
|
||
|
|
||
| def test_multiplexed_publish( | ||
| topic1, topic2, topic1_publisher, topic2_publisher, multiplexed_publisher | ||
| ): | ||
| topic1_publisher.__enter__.return_value = topic1_publisher | ||
| topic2_publisher.__enter__.return_value = topic2_publisher | ||
| with multiplexed_publisher: | ||
| multiplexed_publisher.publish(topic1, data=b"abc") | ||
| topic1_publisher.__enter__.assert_called_once() | ||
| topic1_publisher.publish.assert_called_once_with(data=b"abc", ordering_key="") | ||
| multiplexed_publisher.publish(topic2, data=b"abc") | ||
| topic2_publisher.__enter__.assert_called_once() | ||
| topic2_publisher.publish.assert_called_once_with(data=b"abc", ordering_key="") | ||
| topic1_publisher.__exit__.assert_called_once() | ||
| topic2_publisher.__exit__.assert_called_once() | ||
|
|
||
|
|
||
| def test_publisher_init_failure(topic1, topic1_publisher, multiplexed_publisher): | ||
| topic1_publisher.__enter__.side_effect = GoogleAPICallError("error") | ||
| with multiplexed_publisher: | ||
| future = multiplexed_publisher.publish(topic1, data=b"abc") | ||
| with pytest.raises(GoogleAPICallError): | ||
| future.result() |
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.