From 21da13ab69055b64e5e29c16521a7b495a789ab8 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Wed, 11 Jul 2018 11:38:58 -0400 Subject: [PATCH] Fix failing test on blockchain --- lib/cmds/blockchain/blockchain.js | 15 +++++++++++++-- lib/core/proxy.js | 9 +++++---- test/blockchain.js | 2 ++ test/processLauncher.js | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index bba94c715..cdbf76473 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -88,12 +88,21 @@ Blockchain.prototype.setupProxy = function() { let ipcObject = new Ipc({ipcRole: 'client'}); - proxy.serve(ipcObject, this.config.rpcHost, this.config.rpcPort, false); - proxy.serve(ipcObject, this.config.wsHost, this.config.wsPort, true); + this.rpcProxy = proxy.serve(ipcObject, this.config.rpcHost, this.config.rpcPort, false); + this.wsProxy = proxy.serve(ipcObject, this.config.wsHost, this.config.wsPort, true); this.config.rpcPort += constants.blockchain.servicePortOnProxy; this.config.wsPort += constants.blockchain.servicePortOnProxy; }; +Blockchain.prototype.shutdownProxy = function() { + if (!this.config.proxy) { + return; + } + + this.rpcProxy.close(); + this.wsProxy.close(); +} + Blockchain.prototype.runCommand = function(cmd, options, callback) { console.log(__("running: %s", cmd.underline).green); if (this.blockchainConfig.silent) { @@ -204,6 +213,8 @@ Blockchain.prototype.readyCallback = function() { }; Blockchain.prototype.kill = function() { + this.shutdownProxy(); + if (this.child) { this.child.kill(); } diff --git a/lib/core/proxy.js b/lib/core/proxy.js index df12cd08c..241a3bf82 100644 --- a/lib/core/proxy.js +++ b/lib/core/proxy.js @@ -3,7 +3,7 @@ const http = require('http'); const constants = require('../constants.json'); let commList = {}; -let transactions = {}; +let transactions = {}; let receipts = {}; const parseRequest = function(reqBody){ @@ -42,7 +42,7 @@ const parseResponse = function(ipc, resBody){ commList[receipts[jsonO.id]].blockNumber = jsonO.result.blockNumber; commList[receipts[jsonO.id]].gasUsed = jsonO.result.gasUsed; commList[receipts[jsonO.id]].status = jsonO.result.status; - + if(ipc.connected && !ipc.connecting){ ipc.request('log', commList[receipts[jsonO.id]]); } else { @@ -109,16 +109,17 @@ exports.serve = function(ipc, host, port, ws){ parseResponse(ipc, data.toString().substr(data.indexOf("{"))); }); }); - + proxy.on('proxyReqWs', (proxyReq, req, socket) => { var parser = new WsParser(0, false); socket.pipe(parser); parser.on('frame', function (frame) { parseRequest(frame.data); }); - + }); } server.listen(port); + return server; }; diff --git a/test/blockchain.js b/test/blockchain.js index a4efeacd3..52bfc4319 100644 --- a/test/blockchain.js +++ b/test/blockchain.js @@ -50,6 +50,7 @@ describe('embark.Blockchain', function () { config.rpcPort += constants.blockchain.servicePortOnProxy; } assert.deepEqual(blockchain.config, config); + blockchain.kill(); done(); }); }); @@ -94,6 +95,7 @@ describe('embark.Blockchain', function () { } assert.deepEqual(blockchain.config, config); + blockchain.kill(); done(); }); }); diff --git a/test/processLauncher.js b/test/processLauncher.js index 8fa8f238f..64f83590f 100644 --- a/test/processLauncher.js +++ b/test/processLauncher.js @@ -1,7 +1,7 @@ /*global describe, it, before, beforeEach*/ const assert = require('assert'); const sinon = require('sinon'); -const TestLogger = require('../lib/tests/test_logger.js'); +const TestLogger = require('../lib/tests/test_logger'); const ProcessLauncher = require('../lib/process/processLauncher'); describe('ProcessWrapper', () => {