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

Commit fddc2e7

Browse files
fix: update to work with latest node types (changed the return type of Stream.destroy()) (#1464)
* test(nodejs): remove 15 add 16 (#1322) Source-Link: googleapis/synthtool@6981da4 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:3563b6b264989c4f5aa31a3682e4df36c95756cfef275d3201508947cbfc511e * fix: update to work with latest node types (changed the return type of Stream.destroy()) * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 38fba8b commit fddc2e7

10 files changed

Lines changed: 20 additions & 50 deletions

File tree

.github/.OwlBot.lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
docker:
22
image: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest
3-
digest: sha256:f092066de33d4a2a13ab13c8fa9dcb4f6b96fa1fb7d391bf19cd0c4921d997c0
3+
digest: sha256:3563b6b264989c4f5aa31a3682e4df36c95756cfef275d3201508947cbfc511e

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node: [10, 12, 14, 15]
12+
node: [10, 12, 14, 16]
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"precompile": "gts clean"
4848
},
4949
"dependencies": {
50-
"@google-cloud/paginator": "^3.0.0",
50+
"@google-cloud/paginator": "^3.0.6",
5151
"@google-cloud/precise-date": "^2.0.0",
5252
"@google-cloud/projectify": "^2.0.0",
5353
"@google-cloud/promisify": "^2.0.0",
@@ -72,7 +72,7 @@
7272
"@types/mocha": "^8.0.0",
7373
"@types/mv": "^2.1.0",
7474
"@types/ncp": "^2.0.1",
75-
"@types/node": "^14.0.0",
75+
"@types/node": "^16.0.0",
7676
"@types/proxyquire": "^1.3.28",
7777
"@types/sinon": "^10.0.0",
7878
"@types/tmp": "^0.2.0",

protos/protos.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/protos.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/message-stream.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,6 @@ export class MessageStream extends PassThrough {
151151
);
152152
this._keepAliveHandle.unref();
153153
}
154-
/**
155-
* Destroys the stream and any underlying streams.
156-
*
157-
* @param {error?} error An error to emit, if any.
158-
* @private
159-
*/
160-
destroy(error?: Error | null): void {
161-
// We can't assume Node has taken care of this in <14.
162-
if (this.destroyed) {
163-
return;
164-
}
165-
super.destroy(error ? error : undefined);
166-
}
167154
/**
168155
* Destroys the stream and any underlying streams.
169156
*
@@ -172,7 +159,6 @@ export class MessageStream extends PassThrough {
172159
* @private
173160
*/
174161
_destroy(error: Error | null, callback: (error: Error | null) => void): void {
175-
this.destroyed = true;
176162
clearInterval(this._keepAliveHandle);
177163

178164
for (const stream of this._streams.keys()) {
@@ -214,7 +200,8 @@ export class MessageStream extends PassThrough {
214200
try {
215201
client = await this._getClient();
216202
} catch (e) {
217-
this.destroy(e);
203+
const err = e as Error;
204+
this.destroy(err);
218205
}
219206

220207
if (this.destroyed) {
@@ -244,7 +231,8 @@ export class MessageStream extends PassThrough {
244231
try {
245232
await this._waitForClientReady(client);
246233
} catch (e) {
247-
this.destroy(e);
234+
const err = e as Error;
235+
this.destroy(err);
248236
}
249237
}
250238
/**
@@ -386,7 +374,8 @@ export class MessageStream extends PassThrough {
386374
try {
387375
await promisify(client.waitForReady).call(client, deadline);
388376
} catch (e) {
389-
throw new ChannelError(e);
377+
const err = e as Error;
378+
throw new ChannelError(err);
390379
}
391380
}
392381
}

test/message-stream.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ const FAKE_CLIENT_CONFIG = {
3838
},
3939
};
4040

41-
// just need this for unit tests.. we have a ponyfill for destroy on
42-
// MessageStream and gax streams use Duplexify
43-
function destroy(stream: Duplex, err?: Error): void {
44-
process.nextTick(() => {
45-
if (err) {
46-
stream.emit('error', err);
47-
}
48-
stream.emit('close');
49-
});
50-
}
51-
5241
interface StreamState {
5342
highWaterMark: number;
5443
}
@@ -68,12 +57,6 @@ class FakePassThrough extends PassThrough {
6857
super(options);
6958
this.options = options;
7059
}
71-
destroy(err?: Error): void {
72-
if (typeof super.destroy === 'function') {
73-
return super.destroy(err);
74-
}
75-
destroy(this, err);
76-
}
7760
}
7861

7962
class FakeGrpcStream extends Duplex {
@@ -95,12 +78,6 @@ class FakeGrpcStream extends Duplex {
9578
this.end();
9679
});
9780
}
98-
destroy(err?: Error): void {
99-
if (typeof super.destroy === 'function') {
100-
return super.destroy(err);
101-
}
102-
destroy(this, err);
103-
}
10481
_write(chunk: object, encoding: string, callback: Function): void {
10582
callback();
10683
}

test/snapshot.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as assert from 'assert';
16+
import {ServiceError} from 'google-gax';
1617
import {describe, it, beforeEach, before, after, afterEach} from 'mocha';
1718
import * as proxyquire from 'proxyquire';
1819
import * as sinon from 'sinon';
@@ -158,7 +159,7 @@ describe('Snapshot', () => {
158159
});
159160

160161
const callback = stub.lastCall.args[2];
161-
setImmediate(callback, fakeError, null, fakeResponse);
162+
setImmediate(callback, fakeError as ServiceError, null, fakeResponse);
162163
});
163164

164165
it('should return the correct snapshot', done => {

test/subscriber.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,16 @@ describe('Subscriber', () => {
556556
stream.emit('error', fakeError);
557557
});
558558

559-
it('should close the subscriber if stream closes unexpectedly', () => {
559+
it('should close the subscriber if stream closes unexpectedly', done => {
560560
const stub = sandbox.stub(subscriber, 'close');
561561
const stream: FakeMessageStream = stubs.get('messageStream');
562562

563563
stream.emit('close');
564564

565-
assert.strictEqual(stub.callCount, 1);
565+
process.nextTick(() => {
566+
assert.strictEqual(stub.callCount, 1);
567+
done();
568+
});
566569
});
567570

568571
it('should add messages to the inventory', done => {

test/subscription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ describe('Subscription', () => {
393393
});
394394

395395
const callback = stub.lastCall.args[3];
396-
setImmediate(callback, fakeErr, null, fakeResponse);
396+
setImmediate(callback, fakeErr as ServiceError, null, fakeResponse);
397397
});
398398

399399
it('should update the subscription', done => {

0 commit comments

Comments
 (0)