Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions auto_submit/lib/request_handling/pubsub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,21 @@ class PubSub {
///
/// The PubSub system can remove the relevant messages from the subscription.
Future<void> acknowledge(String subscription, String ackId) async {
final Client httpClient = await clientViaApplicationDefaultCredentials(
scopes: <String>[pubsub.PubsubApi.pubsubScope],
);
final pubsubApi = pubsub.PubsubApi(httpClient);
final ackIds = <String>[ackId];
final acknowledgeRequest = pubsub.AcknowledgeRequest(ackIds: ackIds);
await pubsubApi.projects.subscriptions.acknowledge(
acknowledgeRequest,
'${Config.pubsubSubscriptionsPrefix}/$subscription',
);
try {
final Client httpClient = await clientViaApplicationDefaultCredentials(
scopes: <String>[pubsub.PubsubApi.pubsubScope],
);
final pubsubApi = pubsub.PubsubApi(httpClient);
final ackIds = <String>[ackId];
final acknowledgeRequest = pubsub.AcknowledgeRequest(ackIds: ackIds);
await pubsubApi.projects.subscriptions.acknowledge(
acknowledgeRequest,
'${Config.pubsubSubscriptionsPrefix}/$subscription',
);
} catch (e) {
log.error(
'Failed to acknowledge message $ackId for subscription $subscription: $e',
);
}
}
}
19 changes: 19 additions & 0 deletions auto_submit/test/request_handling/pubsub_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2026 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:auto_submit/request_handling/pubsub.dart';
import 'package:test/test.dart';

void main() {
group('PubSub', () {
test('acknowledge handles exceptions gracefully', () async {
const pubsub = PubSub();
// This should not throw even if credentials are missing or API fails.
await expectLater(
pubsub.acknowledge('test-sub', 'test-ack-id'),
completes,
);
});
});
}
Loading