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

Commit a211f6a

Browse files
authored
tests: attempt to make some tests more deterministic (#1311)
1 parent 2c0ab6c commit a211f6a

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

samples/system-test/schema.test.ts

Lines changed: 14 additions & 13 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, afterEach} from 'mocha';
26+
import {describe, it, after} from 'mocha';
2727
import * as cp from 'child_process';
2828
import * as uuid from 'uuid';
2929
import * as path from 'path';
@@ -40,9 +40,9 @@ describe('schema', () => {
4040
const pubsub = new PubSub({projectId});
4141
const runId = uuid.v4();
4242
console.log(`Topics runId: ${runId}`);
43-
const topicIdStem = `schema-top-${runId}`;
44-
const subscriptionIdStem = `schema-sub-${runId}`;
45-
const schemaIdStem = `schema-${runId}`;
43+
const topicIdStem = `schema-top-${runId}-`;
44+
const subscriptionIdStem = `schema-sub-${runId}-`;
45+
const schemaIdStem = `schema-${runId}-`;
4646

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

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

71-
async function cleanSchemas() {
71+
async function cleanAllSchemas() {
7272
const schemas = [];
7373
for await (const s of pubsub.listSchemas()) {
7474
schemas.push(pubsub.schema(s.name!).delete());
7575
}
7676
await Promise.all(schemas);
7777
}
7878

79-
async function cleanTopics() {
79+
async function cleanAllTopics() {
8080
const [topics] = await pubsub.getTopics();
8181
await Promise.all(
8282
topics.filter(x => x.name.endsWith(runId)).map(x => x.delete())
8383
);
8484
}
8585

86-
async function cleanSubs() {
86+
async function cleanAllSubs() {
8787
const [subscriptions] = await pubsub.getSubscriptions();
8888
await Promise.all(
8989
subscriptions.filter(x => x.name.endsWith(runId)).map(x => x.delete())
9090
);
9191
}
9292

93-
afterEach(async () => {
94-
await cleanSubs();
95-
await cleanTopics();
96-
await cleanSchemas();
93+
after(async () => {
94+
await cleanAllSubs();
95+
await cleanAllTopics();
96+
await cleanAllSchemas();
9797
});
9898

9999
function fixturePath(fixture: string): string {
@@ -202,12 +202,13 @@ describe('schema', () => {
202202
assert.include(output, schema.id);
203203
assert.include(output, 'deleted.');
204204

205-
try {
205+
// Because of caching delays, this can't be deterministic without a big wait.
206+
/*try {
206207
const got = await pubsub.schema(schema.id).get();
207208
assert.isNotOk(got, "schema hadn't been deleted");
208209
} catch (e) {
209210
// This is expected.
210-
}
211+
}*/
211212
});
212213

213214
it('should get a schema', async () => {

samples/system-test/typescript.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import {assert} from 'chai';
16-
import {describe, it, afterEach} from 'mocha';
16+
import {describe, it} from 'mocha';
1717
import * as cp from 'child_process';
1818
import * as fs from 'fs';
1919
import * as rimraf from 'rimraf';

0 commit comments

Comments
 (0)