Skip to content
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

fix(pubsub): pass context into checkOrdering to allow cancel #5316

Merged
merged 6 commits into from Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions pubsub/subscription.go
Expand Up @@ -840,7 +840,7 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes
s.mu.Unlock()
defer func() { s.mu.Lock(); s.receiveActive = false; s.mu.Unlock() }()

s.checkOrdering()
s.checkOrdering(ctx)

maxCount := s.ReceiveSettings.MaxOutstandingMessages
if maxCount == 0 {
Expand Down Expand Up @@ -1033,8 +1033,7 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes
// the roles/viewer or roles/pubsub.viewer role) we will assume
// EnableMessageOrdering to be true.
// See: https://github.com/googleapis/google-cloud-go/issues/3884
func (s *Subscription) checkOrdering() {
ctx := context.Background()
func (s *Subscription) checkOrdering(ctx context.Context) {
cfg, err := s.Config(ctx)
if err != nil {
s.enableOrdering = true
Expand Down
7 changes: 7 additions & 0 deletions pubsub/subscription_test.go
Expand Up @@ -427,4 +427,11 @@ func TestOrdering_CreateSubscription(t *testing.T) {
if !cfg.EnableMessageOrdering {
t.Fatalf("Expected EnableMessageOrdering to be true in %s", orderSub.String())
}

// Test cancellation works as intended with ordering enabled.
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
orderSub.Receive(ctx, func(ctx context.Context, msg *Message) {
msg.Ack()
})
}