Skip to content

test(pubsub): add unit tests for publish hedging queue integration - #9635

Open
feywind wants to merge 2 commits into
pubsub/hedging-queue-integration-and-testsfrom
pubsub/hedging-queue-unit-tests
Open

feywind wants to merge 2 commits into
pubsub/hedging-queue-integration-and-testsfrom
pubsub/hedging-queue-unit-tests

Conversation

@feywind

@feywind feywind commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This PR is Layer 6 of 7 in Stack #9467, which implements Publish Hedging for @google-cloud/pubsub to mitigate high-percentile (p99/p99.9) publish tail latencies by sending backup (hedged) publish RPCs when an in-flight batch takes longer than a configurable hedgeDelay threshold.

Stack Structure

  1. feat(gax): support cancelling API calls via CallOptions.signal #9462 - feat(gax): support AbortSignal cancellation in CallOptions and createApiCall
  2. feat(pubsub): add HedgingOptions validation and token bucket #9463 - feat(pubsub): add HedgingOptions validation and HedgingTokenBucket
  3. feat(pubsub): add CancellationSharer and HedgingScheduler #9464 - feat(pubsub): add CancellationSharer and HedgingScheduler
  4. feat(pubsub): add OpenTelemetry events and logging for hedged publish #9465 - feat(pubsub): add OpenTelemetry events and logging for hedged publish
  5. feat(pubsub): integrate publish hedging into MessageQueue #9466 - feat(pubsub): integrate publish hedging into MessageQueue
  6. test(pubsub): add unit tests for publish hedging queue integration #9635 - test(pubsub): add unit tests for publish hedging queue integration (this PR)
  7. test(pubsub): add publish hedging system tests #9636 - test(pubsub): add publish hedging system tests

Summary of Changes in This PR

This layer adds unit test coverage for the publish hedging queue integration and AbortSignal handling in PubSub.prototype.request:

  • handwritten/pubsub/test/publisher/message-queues.ts:
    • Default hedging behaviour when no hedging occurs.
    • Original attempt (attempt 0) winning after a hedged attempt is dispatched, aborting the hedged attempt via AbortSignal and recording publish end.
    • Hedged attempt winning first, aborting attempt 0 and recording publish end (hedged).
    • Hedged attempt errors being ignored while attempt 0 succeeds.
    • Terminal failure of attempt 0 rejecting the batch and aborting any in-flight hedged attempts.
    • Multiple sequential hedged attempts (attempt 1, attempt 2, ...) at hedgeDelay intervals.
    • Token bucket exhaustion ('Hedging rate limited due to lack of tokens.') and token replenishment over subsequent successful publishes.
    • Ensuring OrderedQueue never hedges.
  • handwritten/pubsub/test/pubsub.ts:
    • Pre-aborted AbortSignal before getClient_ completes and AbortSignal aborted while getClient_ is in flight.

@feywind
feywind added this pull request to stack #9467 October 15, 2026 19:01
@product-auto-label product-auto-label Bot added the api: pubsub Issues related to the Pub/Sub API. label Oct 15, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive unit tests for publish hedging in message queues, refactors existing tests to use async/await, and adds tests to verify that pubsub.request correctly handles aborted signals. The review feedback highlights critical runtime ReferenceErrors in the new tests due to missing namespace qualifiers on Queue and OrderedQueue, and recommends replacing the generic Function type with a more specific callback signature in the pubsub tests.

Comment thread handwritten/pubsub/test/publisher/message-queues.ts
Comment thread handwritten/pubsub/test/publisher/message-queues.ts
Comment thread handwritten/pubsub/test/pubsub.ts Outdated
@feywind
feywind force-pushed the pubsub/hedging-queue-unit-tests branch from 83ff0a2 to 52924b1 Compare October 19, 2026 21:57

This branch has not been deployed

No deployments
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.

1 participant