@@ -23,7 +23,7 @@ import {describe, it, afterEach, beforeEach} from 'mocha';
23
23
import * as sinon from 'sinon' ;
24
24
import { EventEmitter } from 'events' ;
25
25
import { Test } from './testTypes' ;
26
- import { ServiceError , GrpcClient } from 'google-gax' ;
26
+ import { ServiceError , GrpcClient , GoogleError } from 'google-gax' ;
27
27
import { PassThrough } from 'stream' ;
28
28
29
29
const { grpc} = new GrpcClient ( ) ;
@@ -77,12 +77,43 @@ function rowResponse(rowKey: {}) {
77
77
78
78
describe ( 'Bigtable/Table' , ( ) => {
79
79
const bigtable = new Bigtable ( ) ;
80
+ const INSTANCE_NAME = 'fake-instance2' ;
80
81
// eslint-disable-next-line @typescript-eslint/no-explicit-any
81
82
( bigtable as any ) . grpcCredentials = grpc . credentials . createInsecure ( ) ;
82
83
83
84
const INSTANCE = bigtable . instance ( 'instance' ) ;
84
85
const TABLE = INSTANCE . table ( 'table' ) ;
85
86
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
+
86
117
describe ( 'createReadStream' , ( ) => {
87
118
let clock : sinon . SinonFakeTimers ;
88
119
let endCalled : boolean ;
0 commit comments