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
This commit is contained in:
Jonathan Rainville 2019-11-05 12:00:42 -05:00 committed by Iuri Matias
parent bad22075ca
commit 863ae51a2f
3 changed files with 36 additions and 15 deletions

View File

@ -41,7 +41,7 @@ class Geth {
this.registerServiceCheck(); this.registerServiceCheck();
}, },
stopFn: async (cb) => { stopFn: async (cb) => {
await this.events.request("processes:stop", "blockchain"); await this.events.request2("processes:stop", "blockchain");
cb(); cb();
} }
}); });

View File

@ -8,7 +8,6 @@ class SolcProcess extends ProcessWrapper {
super({pingParent: false}); super({pingParent: false});
this._logger = options.logger; this._logger = options.logger;
this._showSpinner = options.showSpinner === true; this._showSpinner = options.showSpinner === true;
this._providerUrl = options.providerUrl;
} }
findImports(filename) { findImports(filename) {

View File

@ -11,30 +11,50 @@ class SolcW {
this.events = options.events; this.events = options.events;
this.ipc = options.ipc; this.ipc = options.ipc;
this.compilerLoaded = false; this.compilerLoaded = false;
this.ipcConnected = false;
this.solcProcess = null; this.solcProcess = null;
this.useDashboard = options.useDashboard; this.useDashboard = options.useDashboard;
this.providerUrl = options.providerUrl;
} }
load_compiler(done) { load_compiler(done) {
const self = this; if (!this.ipc.isClient()) {
if (!self.ipc.isClient()) { return this.load_compiler_internally(done);
return self.load_compiler_internally(done);
} }
if (self.ipc.connected) { this.checkIpcConnection((err) => {
self.compilerLoaded = true;
return done();
}
self.ipc.connect((err) => {
if (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(); 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) { load_compiler_internally(done) {
if (this.compilerLoaded) { if (this.compilerLoaded) {
return done(); return done();
@ -44,7 +64,6 @@ class SolcW {
modulePath: joinPath(__dirname, 'solcP.js'), modulePath: joinPath(__dirname, 'solcP.js'),
logger: this.logger, logger: this.logger,
events: this.events, events: this.events,
providerUrl: this.providerUrl,
silent: false silent: false
}); });
@ -74,6 +93,9 @@ class SolcW {
if (this.ipc.isServer()) { if (this.ipc.isServer()) {
this.ipc.on('compile', this.compile.bind(this)); this.ipc.on('compile', this.compile.bind(this));
this.ipc.on('testConnection', (cb) => {
cb(true);
});
} }
} }
@ -84,7 +106,7 @@ class SolcW {
compile(jsonObj, done) { compile(jsonObj, done) {
const id = uuid(); const id = uuid();
if (this.ipc.isClient() && this.ipc.connected) { if (this.ipcConnected) {
return this.ipc.request('compile', jsonObj, done); return this.ipc.request('compile', jsonObj, done);
} }