diff --git a/src/index.ts b/src/index.ts index 22eb051c5..93ecd1050 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 diff --git a/test/spanner.ts b/test/spanner.ts index 044db7da0..ceca94d24 100644 --- a/test/spanner.ts +++ b/test/spanner.ts @@ -147,6 +147,7 @@ describe('Spanner with mock server', () => { }); after(() => { + spanner.close(); server.tryShutdown(() => {}); delete process.env.SPANNER_EMULATOR_HOST; sandbox.restore();