Skip to content

Conversation

@dbolduc
Copy link
Member

@dbolduc dbolduc commented Dec 23, 2025

Part of the work for #3957

Add a lease loop. The loop runs on end, performing any of the following actions:

  • handle a shutdown
  • flush acks/nacks
  • extend leases
  • accept a new message
  • handle incoming acks/nacks

I combined these things into a struct, but I may change my mind later.

On testing...

TIL: mock.checkpoint(). It means check all the expectations at this exact moment.

I found it easiest to use an Arc<Mutex<Mock>> which allowed me to give the mock to the lease loop AND set expectations on the mock outside of the lease loop.

I also tried to recover the time at which events happen from within the mock expectations, but decided that was more complicated.

Because tokio::test is single threaded (if you want to start_paused = true), I found that I needed to yield the current execution so tokio would actually launch the lease loop. Otherwise it would not launch the lease loop until the first .await point, and the timing was all messed up.

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Dec 23, 2025
@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.77%. Comparing base (97470cb) to head (75ba458).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/pubsub/src/subscriber/lease_loop.rs 87.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4120      +/-   ##
==========================================
- Coverage   94.81%   94.77%   -0.04%     
==========================================
  Files         182      183       +1     
  Lines        6887     6911      +24     
==========================================
+ Hits         6530     6550      +20     
- Misses        357      361       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbolduc dbolduc marked this pull request as ready for review December 23, 2025 03:20
@dbolduc dbolduc requested a review from a team as a code owner December 23, 2025 03:20
suzmue
suzmue previously approved these changes Dec 23, 2025
use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;

/// A convenience struct that groups the components of the lease loop
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: all these comments should end with periods.

Comments should usually be complete sentences. Start with a capital letter, end with a period (.). - https://doc.rust-lang.org/stable/style-guide/#comments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@dbolduc dbolduc merged commit ec5ea57 into googleapis:main Dec 26, 2025
29 checks passed
@dbolduc dbolduc deleted the impl-pubsub-lease-loop-redo branch December 26, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants