Skip to content

Commit

Permalink
fix: add close method to Spanner client (#1416)
Browse files Browse the repository at this point in the history
Adds a close method to the Spanner client that will (try to) clean up the resources
it has in use.

Towards #1306
  • Loading branch information
olavloite committed Jul 7, 2021
1 parent e4fc2a1 commit 69cd0b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.ts
Expand Up @@ -268,6 +268,18 @@ class Spanner extends GrpcService {
};
}

/** Closes this Spanner client and cleans up all resources used by it. */
close(): void {
this.clients_.forEach(c => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const client = c as any;
if (client.operationsClient && client.operationsClient.close) {
client.operationsClient.close();
}
client.close();
});
}

createInstance(
name: string,
config: CreateInstanceRequest
Expand Down
1 change: 1 addition & 0 deletions test/spanner.ts
Expand Up @@ -147,6 +147,7 @@ describe('Spanner with mock server', () => {
});

after(() => {
spanner.close();
server.tryShutdown(() => {});
delete process.env.SPANNER_EMULATOR_HOST;
sandbox.restore();
Expand Down

0 comments on commit 69cd0b4

Please sign in to comment.