Skip to content

Commit

Permalink
fix: verification of fuel-core node killing (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedsalk authored Jul 18, 2024
1 parent d9d0573 commit 98748ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .changeset/neat-bikes-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

fix: verification of all test nodes being killed
22 changes: 0 additions & 22 deletions packages/account/src/test-utils/launchNode-singular-test.test.ts

This file was deleted.

23 changes: 23 additions & 0 deletions packages/account/src/test-utils/launchNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ describe('launchNode', () => {
await waitUntilUnreachable(url);
});

/**
* Spawning the child process in a detached state
* Results in the OS assigning a process group to the child.
* Combining that with `process.kill(-pid)`,
* which sends a "kill process group" signal to the OS,
* ensures that the node will be killed.
*/
it('spawns the fuel-core node in a detached state and kills the process group on cleanup', async () => {
const spawnSpy = vi.spyOn(childProcessMod, 'spawn');
const killSpy = vi.spyOn(process, 'kill');

const { cleanup, pid } = await launchNode();

const spawnOptions = spawnSpy.mock.calls[0][2];
expect(spawnOptions.detached).toBeTruthy();

cleanup();

expect(killSpy).toHaveBeenCalledTimes(1);
// adding a minus prefix kills the process group
expect(killSpy).toHaveBeenCalledWith(-pid);
});

test('should start `fuel-core` node using system binary', async () => {
const spawnSpy = vi.spyOn(childProcessMod, 'spawn');

Expand Down

0 comments on commit 98748ec

Please sign in to comment.