-
Notifications
You must be signed in to change notification settings - Fork 569
feat(pubsub): implement streaming keep-alive logic #34653
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
Open
torreypayne
wants to merge
10
commits into
main
Choose a base branch
from
pubsub-streaming-keepalive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f46e80d
feat(pubsub): implement streaming keep-alive logic
yoshi-automation 6b07f44
fix(pubsub): remediate keep-alive unpause race and timer testability
torreypayne 1219156
fix(pubsub): make keep-alive unit tests deterministic without startin…
torreypayne a7165c9
fix(pubsub): remove test-only env vars, remove buganizer IDs and capi…
torreypayne 0ad78cb
capitalize comment
torreypayne 9461a56
fix(pubsub): disable liveness check during retry backoff and document…
torreypayne cca4878
feat(pubsub): enrich keep-alive timeout diagnostic logs and push clos…
torreypayne 82b508d
docs(pubsub): document timestamp re-initialization and stream_opened …
torreypayne c707629
refactor(pubsub): extract numeric constants on Stream and document st…
torreypayne 4b5d1be
test(pubsub): verify stream_opened is set to false during backoff_and…
torreypayne 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
73 changes: 73 additions & 0 deletions
73
google-cloud-pubsub/test/google/cloud/pubsub/message_listener/bug_regression_test.rb
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,73 @@ | ||
| # Copyright 2026 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 | ||
| # | ||
| # https://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. | ||
|
|
||
| require "helper" | ||
|
|
||
| describe Google::Cloud::PubSub::MessageListener, :bug_regression, :mock_pubsub do | ||
| let(:topic_name) { "topic-name-goes-here" } | ||
| let(:sub_name) { "subscription-name-goes-here" } | ||
| let(:sub_hash) { subscription_hash topic_name, sub_name } | ||
| let(:sub_grpc) { Google::Cloud::PubSub::V1::Subscription.new(sub_hash) } | ||
| let(:subscriber) { Google::Cloud::PubSub::Subscriber.from_grpc sub_grpc, pubsub.service } | ||
|
|
||
| it "waits for exponential backoff before retrying on GRPC::Unavailable" do | ||
| attempts = [] | ||
| pull_res = Google::Cloud::PubSub::V1::StreamingPullResponse.new received_messages: [] | ||
| response_groups = [[GRPC::Unavailable.new("simulated disconnect")], [pull_res]] | ||
| stub = StreamingPullStub.new response_groups | ||
| def stub.streaming_pull_internal request, options = nil | ||
| @attempts ||= [] | ||
| @attempts << Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
| super | ||
| end | ||
| stub.instance_variable_set(:@attempts, attempts) | ||
| subscriber.service.mocked_subscription_admin = stub | ||
|
|
||
| listener = subscriber.listen streams: 1 do |msg| | ||
| end | ||
| listener.start | ||
|
|
||
| retries = 0 | ||
| until attempts.count >= 2 | ||
| fail "stream did not retry" if retries > 200 | ||
| retries += 1 | ||
| sleep 0.05 | ||
| end | ||
|
|
||
| listener.stop | ||
| listener.wait! | ||
|
|
||
| elapsed = attempts[1] - attempts[0] | ||
| puts "\n[b/528401453 Test] Elapsed delay between attempts: #{elapsed.round(3)}s" | ||
| _(elapsed).must_be :>=, 1.0 | ||
| end | ||
|
|
||
| it "shuts down keepalive TimerTask when stream is stopped" do | ||
| pull_res = Google::Cloud::PubSub::V1::StreamingPullResponse.new received_messages: [] | ||
| stub = StreamingPullStub.new [[pull_res]] | ||
| subscriber.service.mocked_subscription_admin = stub | ||
|
|
||
| listener = subscriber.listen streams: 1 do |msg| | ||
| end | ||
| listener.start | ||
| sleep 0.1 | ||
| listener.stop | ||
| listener.wait! | ||
|
|
||
| stream = listener.instance_variable_get(:@stream_pool).first | ||
| keepalive_task = stream.instance_variable_get(:@stream_keepalive_task) | ||
| puts "\n[b/528404815 Test] Keepalive task running state after stop: #{keepalive_task&.running? || false}" | ||
| _(keepalive_task.nil? || !keepalive_task.running?).must_equal true | ||
| end | ||
| end |
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
Oops, something went wrong.
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.