Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
revert changes to server utility and manually manage ganache in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eggplantzzz committed Oct 31, 2022
1 parent ab9f9fd commit bce7533
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
22 changes: 16 additions & 6 deletions packages/truffle/test/scenarios/db/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@ const path = require("path");
const Db = require("@truffle/db");
const { assert } = require("chai");
const CommandRunner = require("../commandRunner");
const Server = require("../server");
const Ganache = require("ganache");
const sandbox = require("../sandbox");
const gql = require("graphql-tag");
let config, project;
let config, project, server1, server2;

describe("truffle db", function () {
before(async function () {
this.timeout(60000);
const projectPath = path.join(__dirname, "..", "..", "sources", "db");
config = await sandbox.create(projectPath);

await Server.start({ port: 8545 });
await Server.start({ port: 9545 });
server1 = await Ganache.server({
logging: {
quiet: true
}
});
server2 = await Ganache.server({
logging: {
quiet: true
}
});
await server1.listen(8545);
await server2.listen(9545);
await CommandRunner.run("migrate --network network1 --quiet", config);
await CommandRunner.run("migrate --network network2 --quiet", config);
const db = Db.connect(config.db);
Expand All @@ -27,7 +36,8 @@ describe("truffle db", function () {
});

after(async function () {
await Server.stop();
await server1.close();
await server2.close();
});

it("creates a project", async function () {
Expand Down
36 changes: 22 additions & 14 deletions packages/truffle/test/scenarios/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const Ganache = require("ganache");
const fs = require("fs-extra");
const glob = require("glob");
let server = null;

module.exports = {
servers: [],

start: async function ({ port }) {
start: async function () {
await this.stop();
if (!process.env.GETH) {
const server = Ganache.server({
server = Ganache.server({
gasLimit: 6721975,
logging: {
quiet: true
Expand All @@ -14,20 +16,26 @@ module.exports = {
instamine: "strict"
}
});
this.servers.push(server);
if (port) {
await server.listen(port);
} else {
await server.listen();
}
await server.listen(8545);
}
},

stop: async function () {
if (this.servers.length > 0) {
for (const server of this.servers) {
await server.close();
}
if (server) {
await server.close();
server = null;
}
await this.cleanUp();
},

cleanUp: function () {
return new Promise((resolve, reject) => {
glob("tmp-*", (err, files) => {
if (err) reject(err);

files.forEach(file => fs.removeSync(file));
resolve();
});
});
}
};

0 comments on commit bce7533

Please # to comment.