From 863ae51a2f10fc2506cec471ee03ad03818a2573 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 5 Nov 2019 12:00:42 -0500 Subject: [PATCH] Fix embark test with --node (#2021) * fix(@embark/solidity): fix solidity ipc connection with blockchain When blockchain was run in another process, the IPC was connected, but the compiler was not loaded, so the IPC calls never returned * fix(@embark/geth): fix cb is not a fn because it needs request2 --- packages/plugins/geth/src/index.js | 2 +- packages/plugins/solidity/src/solcP.js | 1 - packages/plugins/solidity/src/solcW.js | 48 +++++++++++++++++++------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/packages/plugins/geth/src/index.js b/packages/plugins/geth/src/index.js index fdd5b300f..f192e99e5 100644 --- a/packages/plugins/geth/src/index.js +++ b/packages/plugins/geth/src/index.js @@ -41,7 +41,7 @@ class Geth { this.registerServiceCheck(); }, stopFn: async (cb) => { - await this.events.request("processes:stop", "blockchain"); + await this.events.request2("processes:stop", "blockchain"); cb(); } }); diff --git a/packages/plugins/solidity/src/solcP.js b/packages/plugins/solidity/src/solcP.js index 9975d6a2c..fc674bd1a 100644 --- a/packages/plugins/solidity/src/solcP.js +++ b/packages/plugins/solidity/src/solcP.js @@ -8,7 +8,6 @@ class SolcProcess extends ProcessWrapper { super({pingParent: false}); this._logger = options.logger; this._showSpinner = options.showSpinner === true; - this._providerUrl = options.providerUrl; } findImports(filename) { diff --git a/packages/plugins/solidity/src/solcW.js b/packages/plugins/solidity/src/solcW.js index bb241ffe4..bce091f3d 100644 --- a/packages/plugins/solidity/src/solcW.js +++ b/packages/plugins/solidity/src/solcW.js @@ -11,30 +11,50 @@ class SolcW { this.events = options.events; this.ipc = options.ipc; this.compilerLoaded = false; + this.ipcConnected = false; this.solcProcess = null; this.useDashboard = options.useDashboard; - this.providerUrl = options.providerUrl; } load_compiler(done) { - const self = this; - if (!self.ipc.isClient()) { - return self.load_compiler_internally(done); + if (!this.ipc.isClient()) { + return this.load_compiler_internally(done); } - if (self.ipc.connected) { - self.compilerLoaded = true; - return done(); - } - self.ipc.connect((err) => { + this.checkIpcConnection((err) => { if (err) { - return self.load_compiler_internally(done); + return this.load_compiler_internally(done); } - self.compilerLoaded = true; + this.ipcConnected = true; + this.compilerLoaded = true; done(); }); } + checkIpcConnection(cb) { + if (this.ipc.connected) { + this.testIpcConnection(cb); + } + this.ipc.connect((err) => { + if (err) { + // No IPC. Load internally + return cb(err); + } + this.testIpcConnection(cb); + }); + } + + testIpcConnection(cb) { + const connectionTimeout = setTimeout(() => { + cb('No compiler through IPC connection'); + }, 1000); + this.ipc.request('testConnection', () => { + // Connection works, the compiler is available through IPC + clearTimeout(connectionTimeout); + cb(); + }); + } + load_compiler_internally(done) { if (this.compilerLoaded) { return done(); @@ -44,7 +64,6 @@ class SolcW { modulePath: joinPath(__dirname, 'solcP.js'), logger: this.logger, events: this.events, - providerUrl: this.providerUrl, silent: false }); @@ -74,6 +93,9 @@ class SolcW { if (this.ipc.isServer()) { this.ipc.on('compile', this.compile.bind(this)); + this.ipc.on('testConnection', (cb) => { + cb(true); + }); } } @@ -84,7 +106,7 @@ class SolcW { compile(jsonObj, done) { const id = uuid(); - if (this.ipc.isClient() && this.ipc.connected) { + if (this.ipcConnected) { return this.ipc.request('compile', jsonObj, done); }