Skip to content

Commit 10dcd21

Browse files
authored
fix: Integration test close function again (#1103)
* First try * Add after hook * Proper test done for closed client * test description change * Eliminate unnecessary comment * Modify test to reflect change
1 parent a3b8732 commit 10dcd21

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ export class Bigtable {
940940
* that a callback is omitted.
941941
*/
942942
promisifyAll(Bigtable, {
943-
exclude: ['instance', 'operation', 'request'],
943+
exclude: ['close', 'instance', 'operation', 'request'],
944944
});
945945

946946
/**

system-test/read-rows.ts

+32-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {describe, it, afterEach, beforeEach} from 'mocha';
2323
import * as sinon from 'sinon';
2424
import {EventEmitter} from 'events';
2525
import {Test} from './testTypes';
26-
import {ServiceError, GrpcClient} from 'google-gax';
26+
import {ServiceError, GrpcClient, GoogleError} from 'google-gax';
2727
import {PassThrough} from 'stream';
2828

2929
const {grpc} = new GrpcClient();
@@ -77,12 +77,43 @@ function rowResponse(rowKey: {}) {
7777

7878
describe('Bigtable/Table', () => {
7979
const bigtable = new Bigtable();
80+
const INSTANCE_NAME = 'fake-instance2';
8081
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8182
(bigtable as any).grpcCredentials = grpc.credentials.createInsecure();
8283

8384
const INSTANCE = bigtable.instance('instance');
8485
const TABLE = INSTANCE.table('table');
8586

87+
describe('close', () => {
88+
it('should fail when invoking readRows with closed client', async () => {
89+
const instance = bigtable.instance(INSTANCE_NAME);
90+
const table = instance.table('fake-table');
91+
await instance.create({
92+
clusters: {
93+
id: 'fake-cluster3',
94+
location: 'us-west1-c',
95+
nodes: 1,
96+
},
97+
});
98+
await table.create({});
99+
await table.getRows(); // This is done to initialize the data client
100+
await bigtable.close();
101+
try {
102+
await table.getRows();
103+
assert.fail(
104+
'An error should have been thrown because the client is closed'
105+
);
106+
} catch (err: any) {
107+
assert.strictEqual(err.message, 'The client has already been closed.');
108+
}
109+
});
110+
after(async () => {
111+
const bigtableSecondClient = new Bigtable();
112+
const instance = bigtableSecondClient.instance(INSTANCE_NAME);
113+
await instance.delete({});
114+
});
115+
});
116+
86117
describe('createReadStream', () => {
87118
let clock: sinon.SinonFakeTimers;
88119
let endCalled: boolean;

test/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const fakePromisify = Object.assign({}, promisify, {
4848
}
4949
promisified = true;
5050
assert.deepStrictEqual(options.exclude, [
51+
'close',
5152
'instance',
5253
'operation',
5354
'request',

0 commit comments

Comments
 (0)