Skip to content

Commit

Permalink
fix: fix flaky schema and subscription tests (#1518)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
feywind authored Apr 19, 2022
1 parent b68e53b commit 5ff0105
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 150 deletions.
11 changes: 6 additions & 5 deletions samples/synchronousPull.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function main(
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const subscriptionName = 'YOUR_SUBSCRIPTION_NAME';
// const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID';

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

async function synchronousPull() {
const formattedSubscription = subClient.subscriptionPath(
projectId,
subscriptionNameOrId
);
// The low level API client requires a name only.
const formattedSubscription =
subscriptionNameOrId.indexOf('/') >= 0
? subscriptionNameOrId
: subClient.subscriptionPath(projectId, subscriptionNameOrId);

// The maximum number of messages returned for this request.
// Pub/Sub may return fewer than the number specified.
Expand Down
9 changes: 5 additions & 4 deletions samples/synchronousPullWithDeliveryAttempts.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ function main(
const subClient = new v1.SubscriberClient();

async function synchronousPullWithDeliveryAttempts() {
const formattedSubscription = subClient.subscriptionPath(
projectId,
subscriptionNameOrId
);
// The low level API client requires a name only.
const formattedSubscription =
subscriptionNameOrId.indexOf('/') >= 0
? subscriptionNameOrId
: subClient.subscriptionPath(projectId, subscriptionNameOrId);

// The maximum number of messages returned for this request.
// Pub/Sub may return fewer than the number specified.
Expand Down
9 changes: 5 additions & 4 deletions samples/synchronousPullWithLeaseManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ function main(
const subClient = new v1.SubscriberClient();

async function synchronousPullWithLeaseManagement() {
const formattedSubscription = subClient.subscriptionPath(
projectId,
subscriptionNameOrId
);
// The low level API client requires a name only.
const formattedSubscription =
subscriptionNameOrId.indexOf('/') >= 0
? subscriptionNameOrId
: subClient.subscriptionPath(projectId, subscriptionNameOrId);

// The maximum number of messages returned for this request.
// Pub/Sub may return fewer than the number specified.
Expand Down
6 changes: 3 additions & 3 deletions samples/system-test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Topic,
} from '@google-cloud/pubsub';
import {assert} from 'chai';
import {describe, it, after} from 'mocha';
import {describe, it, afterEach} from 'mocha';
import * as cp from 'child_process';
import * as uuid from 'uuid';
import * as path from 'path';
Expand All @@ -39,7 +39,7 @@ describe('schema', () => {
const projectId = process.env.GCLOUD_PROJECT;
const pubsub = new PubSub({projectId});
const runId = uuid.v4();
console.log(`Topics runId: ${runId}`);
console.log(`Schema runId: ${runId}`);
const topicIdStem = `schema-top-${runId}-`;
const subscriptionIdStem = `schema-sub-${runId}-`;
const schemaIdStem = `schema-${runId}-`;
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('schema', () => {
);
}

after(async () => {
afterEach(async () => {
await cleanAllSubs();
await cleanAllTopics();
await cleanAllSchemas();
Expand Down
Loading

0 comments on commit 5ff0105

Please sign in to comment.