Skip to content

Commit 4815418

Browse files
committed
Merge branch 'just-pick-failing-readrow-test' of https://github.com/googleapis/nodejs-bigtable into 359913994-third-PR-CSM
# Conflicts: # system-test/read-rows.ts
2 parents a89b6aa + 5daed23 commit 4815418

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

system-test/data/read-rows-retry-test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
{ "startKeyClosed": "a", "endKeyClosed": "c" },
150150
{ "startKeyClosed": "x", "endKeyClosed": "z" }
151151
] },
152-
{ "rowKeys": [],
152+
{ "rowKeys": [],
153153
"rowRanges": [ { "startKeyClosed": "x", "endKeyClosed": "z" } ] }
154154
],
155155
"responses": [

system-test/read-rows.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {ServiceError, GrpcClient, GoogleError, CallOptions} from 'google-gax';
2727
import {PassThrough} from 'stream';
2828
import * as proxyquire from 'proxyquire';
2929
import {TabularApiSurface} from '../src/tabular-api-surface';
30-
import {Row} from '../src';
30+
import * as mocha from 'mocha';
3131

3232
const {grpc} = new GrpcClient();
3333

@@ -152,7 +152,6 @@ describe('Bigtable/Table', () => {
152152
});
153153

154154
describe('createReadStream', () => {
155-
let clock: sinon.SinonFakeTimers;
156155
let endCalled: boolean;
157156
let error: ServiceError | null;
158157
let requestedOptions: Array<{}>;
@@ -161,18 +160,6 @@ describe('Bigtable/Table', () => {
161160
let stub: sinon.SinonStub;
162161

163162
beforeEach(() => {
164-
clock = sinon.useFakeTimers({
165-
toFake: [
166-
'setTimeout',
167-
'clearTimeout',
168-
'setImmediate',
169-
'clearImmediate',
170-
'setInterval',
171-
'clearInterval',
172-
'Date',
173-
'nextTick',
174-
],
175-
});
176163
endCalled = false;
177164
error = null;
178165
responses = null;
@@ -214,36 +201,48 @@ describe('Bigtable/Table', () => {
214201
});
215202

216203
afterEach(() => {
217-
clock.restore();
218204
stub.restore();
219205
});
220206

221207
tests.forEach(test => {
222-
it(test.name, () => {
208+
it(test.name, (done: mocha.Done) => {
223209
responses = test.responses;
224210
TABLE.maxRetries = test.max_retries;
225211
TABLE.createReadStream(test.createReadStream_options)
226-
.on('data', (row: Row) =>
212+
.on('data', (row: any) =>
227213
rowKeysRead[rowKeysRead.length - 1].push(row.id),
228214
)
229-
.on('end', () => (endCalled = true))
230-
.on('error', (err: ServiceError) => (error = err as ServiceError));
231-
clock.runAll();
215+
.on('end', () => {
216+
endCalled = true;
217+
doAssertionChecks();
218+
})
219+
.on('error', (err: any) => {
220+
error = err as ServiceError;
221+
doAssertionChecks();
222+
});
232223

233-
if (test.error) {
234-
assert(!endCalled, ".on('end') should not have been invoked");
235-
assert.strictEqual(error!.code, test.error);
236-
} else {
237-
assert(endCalled, ".on('end') shoud have been invoked");
238-
assert.ifError(error);
224+
function doAssertionChecks() {
225+
try {
226+
if (test.error) {
227+
assert(!endCalled, ".on('end') should not have been invoked");
228+
assert.strictEqual(error!.code, test.error);
229+
} else {
230+
assert(endCalled, ".on('end') shoud have been invoked");
231+
assert.ifError(error);
232+
}
233+
assert.deepStrictEqual(rowKeysRead, test.row_keys_read);
234+
assert(responses);
235+
assert.strictEqual(
236+
responses.length,
237+
0,
238+
'not all the responses were used',
239+
);
240+
assert.deepStrictEqual(requestedOptions, test.request_options);
241+
done();
242+
} catch (e) {
243+
done(e);
244+
}
239245
}
240-
assert.deepStrictEqual(rowKeysRead, test.row_keys_read);
241-
assert.strictEqual(
242-
responses.length,
243-
0,
244-
'not all the responses were used',
245-
);
246-
assert.deepStrictEqual(requestedOptions, test.request_options);
247246
});
248247
});
249248
});

0 commit comments

Comments
 (0)