This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4671 from trufflesuite/connect-or-start
Internal improvement: refactor connectOrStart
- Loading branch information
Showing
5 changed files
with
91 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["../../.eslintrc.package.json"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const assert = require("chai").assert; | ||
const Develop = require("../develop"); | ||
|
||
describe("connectOrStart test network", async function () { | ||
const ipcOptions = { network: "test" }; | ||
const ganacheOptions = { | ||
host: "127.0.0.1", | ||
network_id: 666, | ||
port: 6969 | ||
}; | ||
|
||
it("starts Ganache when no Ganache instance is running", async function () { | ||
let connection; | ||
try { | ||
connection = await Develop.connectOrStart(ipcOptions, ganacheOptions); | ||
assert.isTrue(connection.started, "A new Ganache server did not spin up"); | ||
assert.isFunction(connection.disconnect, "disconnect is not a function"); | ||
} finally { | ||
if (connection) { | ||
connection.disconnect(); | ||
} | ||
} | ||
}); | ||
|
||
it("connects to an established Ganache instance", async function () { | ||
let connectionOneDisconnect, connectionTwo; | ||
let spawnedGanache; | ||
|
||
try { | ||
//Establish IPC Ganache service | ||
spawnedGanache = await Develop.start(ipcOptions.network, ganacheOptions); | ||
connectionOneDisconnect = await Develop.connect({ | ||
...ipcOptions, | ||
retry: true | ||
}); | ||
|
||
//Test | ||
connectionTwo = await Develop.connectOrStart(ipcOptions, ganacheOptions); | ||
|
||
//Validate | ||
assert.isFalse(connectionTwo.started); | ||
} finally { | ||
//Cleanup IPC2 | ||
if (connectionTwo.disconnect) { | ||
connectionTwo.disconnect(); | ||
} | ||
//Cleanup IPC1 | ||
if (connectionOneDisconnect) { | ||
connectionOneDisconnect(); | ||
} | ||
//Signal Ganache Process to exit | ||
process.kill(spawnedGanache.pid, "SIGHUP"); | ||
//Resolve on confirmation of process exit | ||
await new Promise(resolve => spawnedGanache.on("exit", () => resolve())); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters