wechaty-puppet-service
Version:
Puppet Service for Wechaty
67 lines • 2.68 kB
JavaScript
/**
* @hcfw007, https://wechaty.js.org/contributors/wang-nan/
* related issue: attempt to reconnect gRPC after disconnection
* Scenario: the watchdog tries to restart the service but failed due to the existence of eventstream
* Caused by the grpcClient set to undefined (still working on why this happens) while eventstream still working
* issue: #172, https://github.com/wechaty/puppet-service/issues/172
*
* NodeJS: How Is Logging Enabled for the @grpc/grpc.js Package
* https://stackoverflow.com/a/60935367/1123955
* GRPC_VERBOSITY=DEBUG GRPC_TRACE=all
*/
/// <reference path="./typings.d.ts" />
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tstest_1 = require("tstest");
const wechaty_puppet_mock_1 = require("wechaty-puppet-mock");
const get_port_1 = __importDefault(require("get-port"));
// import whyIsNodeRunning from 'why-is-node-running'
const mod_js_1 = require("../src/mod.js");
(0, tstest_1.test)('gRPC client breaks', async (t) => {
/**
* Huan(202110):
* `insecure_` prefix is required for the TLS version of Puppet Service
* because the `insecure` will be the SNI name of the Puppet Service
* and it will be enforced for the security (required by TLS)
*/
const TOKEN = 'insecure_token';
const PORT = await (0, get_port_1.default)();
const ENDPOINT = '0.0.0.0:' + PORT;
const puppet = new wechaty_puppet_mock_1.PuppetMock();
const spyOnStart = tstest_1.sinon.spy(puppet, 'onStart');
/**
* Puppet Server
*/
const serverOptions = {
endpoint: ENDPOINT,
puppet: puppet,
token: TOKEN,
};
const puppetServer = new mod_js_1.PuppetServer(serverOptions);
await puppetServer.start();
/**
* Puppet Service Client
*/
const puppetOptions = {
endpoint: ENDPOINT,
token: TOKEN,
};
const puppetService = new mod_js_1.PuppetService(puppetOptions);
await puppetService.start();
t.ok(spyOnStart.called, 'should called the puppet server onStart() function');
puppetService.on('error', console.error);
/**
* mock grpcClient break
*/
await puppetService.grpcManager.client.close();
await puppetService.stop();
// get eventStream status
t.throws(() => puppetService.grpcManager, 'should clean grpc after stop()');
// setTimeout(() => whyIsNodeRunning(), 1000)
await puppetServer.stop();
});
//# sourceMappingURL=grpc-stream.spec.js.map
;