Skip to content

Commit 3b92e56

Browse files
JustinBeckwiththiyaguk09
authored andcommitted
test: reap old instances before system tests (googleapis#687)
1 parent 2c141c6 commit 3b92e56

6 files changed

Lines changed: 30 additions & 37 deletions

File tree

handwritten/bigtable/package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"docs": "jsdoc -c .jsdoc.js",
3131
"predocs-test": "npm run docs",
3232
"docs-test": "linkinator docs",
33-
"fix": "gts fix && eslint '**/*.js' --fix",
33+
"fix": "gts fix",
3434
"prelint": "cd samples; npm link ../; npm i",
35-
"lint": "gts check && eslint samples/*.js",
35+
"lint": "gts check",
3636
"prepare": "npm run compile",
3737
"samples-test": "cd samples/ && npm link ../ && npm install && npm test && cd ../",
3838
"snippet-test": "mocha samples/document-snippets/tests/*.js --timeout 600000",
@@ -79,10 +79,6 @@
7979
"@types/uuid": "^7.0.0",
8080
"c8": "^7.1.0",
8181
"codecov": "^3.6.5",
82-
"eslint": "^6.8.0",
83-
"eslint-config-prettier": "^6.10.0",
84-
"eslint-plugin-node": "^11.0.0",
85-
"eslint-plugin-prettier": "^3.1.2",
8682
"google-auth-library": "^6.0.0",
8783
"gts": "2.0.0-alpha.9",
8884
"jsdoc": "^3.6.3",
@@ -96,8 +92,6 @@
9692
"null-loader": "^3.0.0",
9793
"p-queue": "^6.0.2",
9894
"pack-n-play": "^1.0.0-2",
99-
"power-assert": "^1.6.1",
100-
"prettier": "^1.19.1",
10195
"proxyquire": "^2.0.0",
10296
"sinon": "^9.0.1",
10397
"ts-loader": "^6.2.1",

handwritten/bigtable/system-test/bigtable.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,26 @@ describe('Bigtable', () => {
3535
const APP_PROFILE = INSTANCE.appProfile(APP_PROFILE_ID);
3636
const CLUSTER_ID = generateId('cluster');
3737

38+
async function reapInstances() {
39+
const [instances] = await bigtable.getInstances();
40+
const testInstances = instances
41+
.filter(i => i.id.match(PREFIX))
42+
.filter(i => {
43+
const timeCreated = (i.metadata!.labels!.time_created as {}) as Date;
44+
// Only delete stale resources.
45+
const oneHourAgo = new Date(Date.now() - 3600000);
46+
return !timeCreated || timeCreated <= oneHourAgo;
47+
});
48+
const q = new Q({concurrency: 5});
49+
await Promise.all(
50+
testInstances.map(instance => {
51+
q.add(() => instance.delete());
52+
})
53+
);
54+
}
55+
3856
before(async () => {
57+
await reapInstances();
3958
const [, operation] = await INSTANCE.create({
4059
clusters: [
4160
{
@@ -59,21 +78,7 @@ describe('Bigtable', () => {
5978
});
6079

6180
after(async () => {
62-
const [instances] = await bigtable.getInstances();
63-
const testInstances = instances
64-
.filter(i => i.id.match(PREFIX))
65-
.filter(i => {
66-
const timeCreated = (i.metadata!.labels!.time_created as {}) as Date;
67-
// Only delete stale resources.
68-
const oneHourAgo = new Date(Date.now() - 3600000);
69-
return !timeCreated || timeCreated <= oneHourAgo;
70-
});
71-
const q = new Q({concurrency: 5});
72-
await Promise.all(
73-
testInstances.map(instance => {
74-
q.add(() => instance.delete());
75-
})
76-
);
81+
await INSTANCE.delete().catch(console.error);
7782
});
7883

7984
describe('instances', () => {

handwritten/bigtable/system-test/install.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {readFileSync} from 'fs';
2121
import {describe, it} from 'mocha';
2222

2323
describe('typescript consumer tests', () => {
24-
it('should have correct type signature for typescript users', async function() {
24+
it('should have correct type signature for typescript users', async function () {
2525
this.timeout(300000);
2626
const options = {
2727
packageDir: process.cwd(), // path to your module.
@@ -35,7 +35,7 @@ describe('typescript consumer tests', () => {
3535
await packNTest(options); // will throw upon error.
3636
});
3737

38-
it('should have correct type signature for javascript users', async function() {
38+
it('should have correct type signature for javascript users', async function () {
3939
this.timeout(300000);
4040
const options = {
4141
packageDir: process.cwd(), // path to your module.

handwritten/bigtable/test/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ describe('Bigtable', () => {
633633
[CONFIG.method]: noop,
634634
};
635635
// eslint-disable-next-line @typescript-eslint/no-explicit-any
636-
(fakeV2 as any)[CONFIG.client] = function(options: any) {
636+
(fakeV2 as any)[CONFIG.client] = function (options: any) {
637637
assert.strictEqual(options, bigtable.options[CONFIG.client]);
638638
return fakeClient;
639639
};
@@ -644,7 +644,7 @@ describe('Bigtable', () => {
644644

645645
it('should use the cached client', done => {
646646
// eslint-disable-next-line @typescript-eslint/no-explicit-any
647-
(fakeV2 as any)[CONFIG.client] = function() {
647+
(fakeV2 as any)[CONFIG.client] = function () {
648648
done(new Error('Should not re-instantiate a GAX client.'));
649649
};
650650
bigtable.request(CONFIG);

handwritten/bigtable/test/table.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ FakeRow.formatChunks_ = sinon.spy(chunks => {
7171
});
7272

7373
const FakeChunkTransformer = createFake(ChunkTransformer);
74-
FakeChunkTransformer.prototype._transform = function(
74+
FakeChunkTransformer.prototype._transform = function (
7575
rows: Row[],
7676
enc: {},
7777
next: Function
@@ -808,7 +808,7 @@ describe('Bigtable/Table', () => {
808808
sinon.stub(table, 'row').callsFake(() => {
809809
return {} as Row;
810810
});
811-
FakeChunkTransformer.prototype._transform = function(
811+
FakeChunkTransformer.prototype._transform = function (
812812
chunks: Array<{}>,
813813
enc: {},
814814
next: Function
@@ -990,7 +990,7 @@ describe('Bigtable/Table', () => {
990990
let setTimeoutSpy: sinon.SinonSpy;
991991

992992
beforeEach(() => {
993-
FakeChunkTransformer.prototype._transform = function(
993+
FakeChunkTransformer.prototype._transform = function (
994994
rows: Row[],
995995
enc: {},
996996
next: Function
@@ -1005,10 +1005,7 @@ describe('Bigtable/Table', () => {
10051005
};
10061006

10071007
callCreateReadStream = (options: {}, verify: Function) => {
1008-
table
1009-
.createReadStream(options)
1010-
.on('end', verify)
1011-
.resume(); // The stream starts paused unless it has a `.data()`
1008+
table.createReadStream(options).on('end', verify).resume(); // The stream starts paused unless it has a `.data()`
10121009
// callback.
10131010
};
10141011

handwritten/bigtable/tslint.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)