Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/integration/action/action-integration.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rmdir, isPortOpen } from './test-util';
import { rmdir, isPortOpen, killProcess } from './test-util';
import { Store } from '../../../src/store';
import IpcAction from '../../../src/action/ipc';
import GrpcAction from '../../../src/action/grpc';
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('Action Integration Tests', function() {
});

it('should fund wallet for node1', async () => {
btcdProcess.kill('SIGINT');
await killProcess(btcdProcess.pid);
btcdArgs.miningAddress = store1.walletAddress;
btcdProcess = await startBtcdProcess(btcdArgs);
await nap(NAP_TIME);
Expand Down
13 changes: 13 additions & 0 deletions test/integration/action/test-util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import net from 'net';
import { nap } from '../../../src/helper';

export const rmdir = path => {
if (fs.existsSync(path)) {
Expand All @@ -24,3 +25,15 @@ export const isPortOpen = async port => {
client.connect(port, 'localhost');
});
};

export const killProcess = async pid => {
let terminated = false;
while (!terminated) {
try {
process.kill(pid);
await nap(500);
} catch (e) {
terminated = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if process.kill() is successful? Will it still throw an exception?

Copy link
Contributor Author

@valentinewallace valentinewallace Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If process.kill() is successful, then it will error on the next attempt to kill it because the process doesn't exist anymore. I couldn't find any other way to determine whether the process was actually dead.

Tried process.terminated, tried process.on(SIGINT)/other event handlers. Those could probably work if I put in a sleep after they occur and then restarted btcd, but I wanted to avoid sleeps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. Let's see if this helps.

}
};