diff --git a/.changeset/neat-bikes-melt.md b/.changeset/neat-bikes-melt.md new file mode 100644 index 0000000000..7ff5dd841f --- /dev/null +++ b/.changeset/neat-bikes-melt.md @@ -0,0 +1,4 @@ +--- +--- + +fix: verification of all test nodes being killed diff --git a/packages/account/src/test-utils/launchNode-singular-test.test.ts b/packages/account/src/test-utils/launchNode-singular-test.test.ts deleted file mode 100644 index 17237e0069..0000000000 --- a/packages/account/src/test-utils/launchNode-singular-test.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { launchNode } from './launchNode'; - -/** - * The test runner creates a test environment per file, - * which we can use to isolate the faulty behavior. - */ -/** - * @group node - */ -describe('launchNode-singular-test', () => { - const killedNode = { - url: '', - }; - afterEach(async () => { - await expect(fetch(killedNode.url)).rejects.toThrow('fetch failed'); - }); - test('synchronous cleanup kills node before test runner exits', async () => { - const { cleanup, url } = await launchNode({ loggingEnabled: false }); - killedNode.url = url; - cleanup(); - }); -}); diff --git a/packages/account/src/test-utils/launchNode.test.ts b/packages/account/src/test-utils/launchNode.test.ts index 8353078094..52b59d2a69 100644 --- a/packages/account/src/test-utils/launchNode.test.ts +++ b/packages/account/src/test-utils/launchNode.test.ts @@ -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');