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

Commit 2042a9d

Browse files
committed
tests: fix TestMutateRow_Generic_CloseClient and a few related things
1 parent 2267bc4 commit 2042a9d

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

src/index.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ export class Bigtable {
492492
static Cluster: Cluster;
493493
_metricsConfigManager: ClientSideMetricsConfigManager;
494494
admin: admin.BigtableAdmin;
495+
closed = false;
495496

496497
constructor(options: BigtableOptions = {}) {
497498
// Determine what scopes are needed.
@@ -909,6 +910,17 @@ export class Bigtable {
909910
let gaxStream: gax.CancellableStream;
910911
let stream: AbortableDuplex;
911912

913+
if (this.closed) {
914+
callback?.({
915+
name: 'Closed',
916+
message: 'Bigtable internal client is closed',
917+
code: grpc.status.ABORTED,
918+
details: 'Bigtable internal client is closed',
919+
metadata: new grpc.Metadata(),
920+
});
921+
return;
922+
}
923+
912924
const prepareGaxRequest = (
913925
callback: (err: Error | null, fn?: Function) => void,
914926
) => {
@@ -1026,11 +1038,22 @@ export class Bigtable {
10261038
* Close all bigtable clients. New requests will be rejected but it will not
10271039
* kill connections with pending requests.
10281040
*/
1029-
close(): Promise<void[]> {
1041+
async close(): Promise<void[]> {
1042+
// Close all of the clients.
10301043
const combined = Object.keys(this.api).map(clientType =>
10311044
this.api[clientType].close(),
10321045
);
1033-
return Promise.all(combined);
1046+
const results = await Promise.all(combined);
1047+
1048+
// Clear them out of our cache.
1049+
Object.keys(this.api).forEach(clientType => {
1050+
delete this.api[clientType];
1051+
});
1052+
1053+
// Mark as closed.
1054+
this.closed = true;
1055+
1056+
return results;
10341057
}
10351058

10361059
/**

testproxy/services/close-client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414

1515
import {google} from '../protos/protos';
1616
import {ClientImplMaker, normalizeCallback} from './utils';
17+
import {closeBigtableClient} from './utils/bigtable-client';
1718
type ICloseClientRequest = google.bigtable.testproxy.ICloseClientRequest;
1819
type ICloseClientResponse = google.bigtable.testproxy.ICloseClientResponse;
1920

21+
import {log} from './utils/log';
22+
2023
export const closeClient: ClientImplMaker<
2124
ICloseClientRequest,
2225
ICloseClientResponse
@@ -26,8 +29,12 @@ export const closeClient: ClientImplMaker<
2629
const {clientId} = request;
2730
const bigtable = clientMap.get(clientId!);
2831

32+
log.info('close client %s (%s)', clientId, bigtable ? 'exists' : "doesn't exist");
33+
2934
if (bigtable) {
35+
await closeBigtableClient(bigtable);
3036
await bigtable.close();
37+
log.info('client %s closed', clientId);
3138
}
3239
return {};
3340
});

testproxy/services/create-client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {google} from '../protos/protos';
1818
import * as grpc from '@grpc/grpc-js';
1919
import {Bigtable} from '../../src';
2020
import {createBigtableClient} from './utils/bigtable-client';
21+
import {log} from './utils/log';
2122

2223
function durationToMilliseconds(
2324
duration: google.protobuf.Duration | google.protobuf.IDuration,
@@ -68,6 +69,8 @@ export const createClient: ClientImplMaker<
6869
);
6970
}
7071

72+
log.info('create client %s (%s)', clientId, clientMap.has(clientId) ? 'exists' : "doesn't exist");
73+
7174
if (clientMap.has(clientId)) {
7275
throw Object.assign(new Error(`Client ${clientId} already exists`), {
7376
code: grpc.status.ALREADY_EXISTS,
@@ -99,6 +102,7 @@ export const createClient: ClientImplMaker<
99102
appProfileId: appProfileId!,
100103
clientConfig,
101104
});
105+
log.info('created bigtable client %s', clientId);
102106
createBigtableClient(bigtable);
103107
clientMap.set(clientId!, bigtable);
104108
return {};

testproxy/services/utils/bigtable-client.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,24 @@ export function createBigtableClient(bigtable: Bigtable) {
3737
bigtableAny[v2] = new BigtableClient(bigtable.options.BigtableClient);
3838
}
3939

40-
export function getBigtableClient(bigtable: Bigtable) {
40+
export function getBigtableClient(bigtable: Bigtable): BigtableClient {
4141
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4242
return (bigtable as any)[v2];
4343
}
4444

45-
export async function deleteBigtableClient(bigtable: Bigtable) {
45+
export async function closeBigtableClient(bigtable: Bigtable) {
4646
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4747
const bigtableAny = bigtable as any;
4848

49-
const bigtableClient = bigtableAny[v2];
49+
const bigtableClient = bigtableAny[v2] as BigtableClient;
5050
await bigtableClient.close();
51+
}
52+
53+
export async function deleteBigtableClient(bigtable: Bigtable) {
54+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55+
const bigtableAny = bigtable as any;
56+
57+
await closeBigtableClient(bigtable);
5158

5259
delete bigtableAny[v2];
5360
}

testproxy/services/utils/log.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2025-2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import {loggingUtils as logging} from 'google-gax';
16+
17+
// Debug logger to use with the testproxy.
18+
export const log = logging.log('cbt-testproxy');

0 commit comments

Comments
 (0)