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

tests: attempt to make some tests more deterministic #1311

Merged
merged 1 commit into from
Jun 11, 2021
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
27 changes: 14 additions & 13 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, afterEach} from 'mocha';
import {describe, it, after} from 'mocha';
import * as cp from 'child_process';
import * as uuid from 'uuid';
import * as path from 'path';
Expand All @@ -40,9 +40,9 @@ describe('schema', () => {
const pubsub = new PubSub({projectId});
const runId = uuid.v4();
console.log(`Topics runId: ${runId}`);
const topicIdStem = `schema-top-${runId}`;
const subscriptionIdStem = `schema-sub-${runId}`;
const schemaIdStem = `schema-${runId}`;
const topicIdStem = `schema-top-${runId}-`;
const subscriptionIdStem = `schema-sub-${runId}-`;
const schemaIdStem = `schema-${runId}-`;

// Schemas have a delay between deletion and actual deletion, so
// we have to make unique schema names. It's simplest to do it for topics
Expand All @@ -68,32 +68,32 @@ describe('schema', () => {

const commandFor = (action: string) => `node ${action}.js`;

async function cleanSchemas() {
async function cleanAllSchemas() {
const schemas = [];
for await (const s of pubsub.listSchemas()) {
schemas.push(pubsub.schema(s.name!).delete());
}
await Promise.all(schemas);
}

async function cleanTopics() {
async function cleanAllTopics() {
const [topics] = await pubsub.getTopics();
await Promise.all(
topics.filter(x => x.name.endsWith(runId)).map(x => x.delete())
);
}

async function cleanSubs() {
async function cleanAllSubs() {
const [subscriptions] = await pubsub.getSubscriptions();
await Promise.all(
subscriptions.filter(x => x.name.endsWith(runId)).map(x => x.delete())
);
}

afterEach(async () => {
await cleanSubs();
await cleanTopics();
await cleanSchemas();
after(async () => {
await cleanAllSubs();
await cleanAllTopics();
await cleanAllSchemas();
});

function fixturePath(fixture: string): string {
Expand Down Expand Up @@ -202,12 +202,13 @@ describe('schema', () => {
assert.include(output, schema.id);
assert.include(output, 'deleted.');

try {
// Because of caching delays, this can't be deterministic without a big wait.
/*try {
bcoe marked this conversation as resolved.
Show resolved Hide resolved
const got = await pubsub.schema(schema.id).get();
assert.isNotOk(got, "schema hadn't been deleted");
} catch (e) {
// This is expected.
}
}*/
});

it('should get a schema', async () => {
Expand Down
2 changes: 1 addition & 1 deletion samples/system-test/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import {assert} from 'chai';
import {describe, it, afterEach} from 'mocha';
import {describe, it} from 'mocha';
import * as cp from 'child_process';
import * as fs from 'fs';
import * as rimraf from 'rimraf';
Expand Down