Skip to content

Commit 4a772ce

Browse files
Seulgi Kimmergify[bot]
authored andcommitted
Make a node for e2e test be able to use IPC
1 parent 86968c7 commit 4a772ce

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

test/src/e2e.long/discovery5.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ describe("discovery5 nodes", function() {
2727
nodes = [new CodeChain()];
2828
bootstrapNode = nodes[0];
2929

30-
const startBootstrap = bootstrapNode.start([
31-
"--discovery-refresh",
32-
"50"
33-
]);
30+
const startBootstrap = bootstrapNode.start({
31+
argv: ["--discovery-refresh", "50"]
32+
});
3433

3534
const nonBootstrapNodes = [];
3635
for (let i = 1; i < numOfNodes; i++) {
@@ -43,12 +42,14 @@ describe("discovery5 nodes", function() {
4342

4443
await Promise.all(
4544
nonBootstrapNodes.map(node =>
46-
node.start([
47-
"--bootstrap-addresses",
48-
`127.0.0.1:${bootstrapNode.port}`,
49-
"--discovery-refresh",
50-
"50"
51-
])
45+
node.start({
46+
argv: [
47+
"--bootstrap-addresses",
48+
`127.0.0.1:${bootstrapNode.port}`,
49+
"--discovery-refresh",
50+
"50"
51+
]
52+
})
5253
)
5354
);
5455
});

test/src/e2e.long/futureTransaction.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("Handle future transactions", function() {
2525
beforeEach(async function() {
2626
nodeA = new CodeChain();
2727

28-
await nodeA.start(["--no-tx-relay"]);
28+
await nodeA.start({ argv: ["--no-tx-relay"] });
2929
});
3030

3131
it("Alone", async function() {
@@ -42,7 +42,7 @@ describe("Handle future transactions", function() {
4242
beforeEach(async function() {
4343
this.timeout(60_000);
4444
nodeB = new CodeChain();
45-
await nodeB.start(["--no-tx-relay"]);
45+
await nodeB.start({ argv: ["--no-tx-relay"] });
4646
await promiseExpect.shouldFulfill("connect", nodeB.connect(nodeA));
4747
});
4848

test/src/e2e.long/sync2.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ describe("sync 2 nodes", function() {
202202
nodeB = new CodeChain();
203203

204204
await Promise.all([
205-
nodeA.start(["--no-tx-relay"]),
206-
nodeB.start(["--no-tx-relay"])
205+
nodeA.start({ argv: ["--no-tx-relay"] }),
206+
nodeB.start({ argv: ["--no-tx-relay"] })
207207
]);
208208
await nodeA.connect(nodeB);
209209

test/src/helper/spawn.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ export default class CodeChain {
124124
mkdirp.sync(`${projectRoot}/keys/`);
125125
mkdirp.sync(`${projectRoot}/test/log/`);
126126
this._dbPath = mkdtempSync(`${projectRoot}/db/`);
127-
this._ipcPath = `/tmp/jsonrpc.${this.id}.ipc`;
127+
this._ipcPath = `/tmp/jsonrpc.${new Date()
128+
.toISOString()
129+
.replace(/[-:.]/g, "_")}.${this.id}.ipc`;
128130
this._keysPath = mkdtempSync(`${projectRoot}/keys/`);
129131
if (additionalKeysPath) {
130132
this.keyFileMovePromise = new Promise((resolve, reject) => {
@@ -149,11 +151,18 @@ export default class CodeChain {
149151
this.isTestFailed = false;
150152
}
151153

152-
public async start(
153-
argv: string[] = [],
154-
logLevel = "trace,mio=warn,tokio=warn,hyper=warn,timer=warn",
155-
disableLog = false
156-
) {
154+
public async start(params?: {
155+
argv?: string[];
156+
logLevel?: string;
157+
disableLog?: boolean;
158+
disableIpc?: boolean;
159+
}) {
160+
const {
161+
argv = [],
162+
logLevel = "trace,mio=warn,tokio=warn,hyper=warn,timer=warn",
163+
disableLog = false,
164+
disableIpc = true
165+
} = params || {};
157166
if (this.keyFileMovePromise) {
158167
await this.keyFileMovePromise;
159168
}
@@ -162,18 +171,24 @@ export default class CodeChain {
162171
// NOTE: https://github.com/CodeChain-io/codechain/issues/348
163172
process.env.WAIT_BEFORE_SHUTDOWN = "0";
164173

174+
const baseArgs = [...this.argv, ...argv];
175+
if (disableIpc) {
176+
baseArgs.push("--no-ipc");
177+
} else {
178+
baseArgs.push("--ipc-path");
179+
baseArgs.push(this.ipcPath);
180+
}
181+
165182
// Resolves when CodeChain initialization completed.
166183
return new Promise((resolve, reject) => {
167184
this.process = spawn(
168185
`target/${useDebugBuild ? "debug" : "release"}/codechain`,
169186
[
170-
...this.argv,
171-
...argv,
187+
...baseArgs,
172188
"--chain",
173189
this.chain,
174190
"--db-path",
175191
this.dbPath,
176-
"--no-ipc",
177192
"--keys-path",
178193
this.keysPath,
179194
"--no-ws",

0 commit comments

Comments
 (0)