From d516570653105c69db553b67f0f03a36ffd44182 Mon Sep 17 00:00:00 2001 From: GP Date: Thu, 19 Sep 2019 10:55:23 +0530 Subject: [PATCH] Repro for https://github.com/grpc/grpc-node/issues/708#issuecomment-532522513 --- src/bug-repro.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bug-repro.ts diff --git a/src/bug-repro.ts b/src/bug-repro.ts new file mode 100644 index 0000000..b1495c5 --- /dev/null +++ b/src/bug-repro.ts @@ -0,0 +1,42 @@ +import { Client, credentials } from 'grpc'; +import { SubscribeRequest, CreateStreamRequest } from '../grpc/generated/api_pb'; +import { APIClient } from '.'; + +const ADDRESS = 'localhost:9292'; +const CREDENTIALS = credentials.createInsecure(); +const STREAM_NAME = 'test-1'; +const SUBJECT = 'test-subject-1'; + +const connection = new Client(ADDRESS, CREDENTIALS); +connection.waitForReady(10000, () => { + console.log('connection ready!'); + const client = new APIClient(ADDRESS, CREDENTIALS, { + channelOverride: connection.getChannel(), // Reuse the working channel for APIClient. + }); + const createRequest = new CreateStreamRequest(); + createRequest.setName(STREAM_NAME); + createRequest.setSubject(SUBJECT); + client.createStream(createRequest, (err) => { + console.log('stream created! now subscribing...'); + const subscribeRequest = new SubscribeRequest(); + subscribeRequest.setStream(STREAM_NAME); + const subscription = client.subscribe(subscribeRequest); + + subscription.on('error', err => { + console.log('> subscribe error = ', err); + }); + subscription.on('status', data => { + console.log('> subscribe on status = ', data); + }); + subscription.on('end', () => { + console.log('> subscription ended!'); + }); + subscription.on('close', () => { + console.log('> subscription closed!'); + }); + + subscription.on('data', data => { + console.log('> subscription data = ', data); + }); + }); +});