Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Commit 5ff0105

Browse files
authored
fix: fix flaky schema and subscription tests (#1518)
* tests: make another attempt and cleaning up the schema test flakiness * tests: rework subscription tests to try to fix flakiness * samples: allow subscription IDs in sync pull samples
1 parent b68e53b commit 5ff0105

5 files changed

Lines changed: 194 additions & 150 deletions

File tree

samples/synchronousPull.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function main(
3636
* TODO(developer): Uncomment these variables before running the sample.
3737
*/
3838
// const projectId = 'YOUR_PROJECT_ID';
39-
// const subscriptionName = 'YOUR_SUBSCRIPTION_NAME';
39+
// const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID';
4040

4141
// Imports the Google Cloud client library. v1 is for the lower level
4242
// proto access.
@@ -46,10 +46,11 @@ function main(
4646
const subClient = new v1.SubscriberClient();
4747

4848
async function synchronousPull() {
49-
const formattedSubscription = subClient.subscriptionPath(
50-
projectId,
51-
subscriptionNameOrId
52-
);
49+
// The low level API client requires a name only.
50+
const formattedSubscription =
51+
subscriptionNameOrId.indexOf('/') >= 0
52+
? subscriptionNameOrId
53+
: subClient.subscriptionPath(projectId, subscriptionNameOrId);
5354

5455
// The maximum number of messages returned for this request.
5556
// Pub/Sub may return fewer than the number specified.

samples/synchronousPullWithDeliveryAttempts.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ function main(
4646
const subClient = new v1.SubscriberClient();
4747

4848
async function synchronousPullWithDeliveryAttempts() {
49-
const formattedSubscription = subClient.subscriptionPath(
50-
projectId,
51-
subscriptionNameOrId
52-
);
49+
// The low level API client requires a name only.
50+
const formattedSubscription =
51+
subscriptionNameOrId.indexOf('/') >= 0
52+
? subscriptionNameOrId
53+
: subClient.subscriptionPath(projectId, subscriptionNameOrId);
5354

5455
// The maximum number of messages returned for this request.
5556
// Pub/Sub may return fewer than the number specified.

samples/synchronousPullWithLeaseManagement.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ function main(
4646
const subClient = new v1.SubscriberClient();
4747

4848
async function synchronousPullWithLeaseManagement() {
49-
const formattedSubscription = subClient.subscriptionPath(
50-
projectId,
51-
subscriptionNameOrId
52-
);
49+
// The low level API client requires a name only.
50+
const formattedSubscription =
51+
subscriptionNameOrId.indexOf('/') >= 0
52+
? subscriptionNameOrId
53+
: subClient.subscriptionPath(projectId, subscriptionNameOrId);
5354

5455
// The maximum number of messages returned for this request.
5556
// Pub/Sub may return fewer than the number specified.

samples/system-test/schema.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
Topic,
2424
} from '@google-cloud/pubsub';
2525
import {assert} from 'chai';
26-
import {describe, it, after} from 'mocha';
26+
import {describe, it, afterEach} from 'mocha';
2727
import * as cp from 'child_process';
2828
import * as uuid from 'uuid';
2929
import * as path from 'path';
@@ -39,7 +39,7 @@ describe('schema', () => {
3939
const projectId = process.env.GCLOUD_PROJECT;
4040
const pubsub = new PubSub({projectId});
4141
const runId = uuid.v4();
42-
console.log(`Topics runId: ${runId}`);
42+
console.log(`Schema runId: ${runId}`);
4343
const topicIdStem = `schema-top-${runId}-`;
4444
const subscriptionIdStem = `schema-sub-${runId}-`;
4545
const schemaIdStem = `schema-${runId}-`;
@@ -90,7 +90,7 @@ describe('schema', () => {
9090
);
9191
}
9292

93-
after(async () => {
93+
afterEach(async () => {
9494
await cleanAllSubs();
9595
await cleanAllTopics();
9696
await cleanAllSchemas();

0 commit comments

Comments
 (0)