Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable fuel-core node cleanup to work in Bun #3438

Merged
merged 15 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
5 changes: 5 additions & 0 deletions .changeset/wise-ladybugs-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

fix: enable `fuel-core` node cleanup to work in Bun
4 changes: 2 additions & 2 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@
"ramda": "^0.30.1"
},
"devDependencies": {
"type-fest": "^4.26.1",
"@fuel-ts/hasher": "workspace:*",
"@fuel-ts/math": "workspace:*",
"@fuel-ts/utils": "workspace:*",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/typescript": "^4.0.9",
"@graphql-codegen/typescript-generic-sdk": "^4.0.1",
"@graphql-codegen/typescript-operations": "^4.2.3",
"@internal/utils": "workspace:*",
"@types/ramda": "^0.30.2",
"get-graphql-schema": "^2.1.2",
"@internal/utils": "workspace:*"
"type-fest": "^4.26.1"
}
}
18 changes: 18 additions & 0 deletions packages/account/src/test-utils/launchNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ vi.mock('fs', async () => {
* @group node
*/
describe('launchNode', () => {
beforeEach(() => {
vi.spyOn(console, 'log').mockImplementation(() => {});
});
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved

test('using ephemeral port 0 is possible', async () => {
const { cleanup, port, url } = await launchNode({ port: '0' });
expect(await fetch(url)).toBeTruthy();
Expand Down Expand Up @@ -252,4 +256,18 @@ describe('launchNode', () => {
`fuel-core node under pid ${pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
);
});

test('should clean up when unable to kill process with "RangeError: pid must be a positive integer" error', async () => {
const killSpy = vi.spyOn(process, 'kill').mockImplementationOnce(() => {
throw new RangeError('pid must be a positive integer');
});

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

cleanup();

expect(killSpy).toBeCalledTimes(2);
expect(killSpy).toBeCalledWith(-pid);
expect(killSpy).toBeCalledWith(+pid);
});
});
4 changes: 4 additions & 0 deletions packages/account/src/test-utils/launchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export const launchNode = async ({
console.log(
`fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
);
} else if (error.message.includes('pid must be a positive integer')) {
// This is a workaround for a bug with Bun.
// See: https://github.com/oven-sh/bun/issues/8787
process.kill(+child.pid);
} else {
throw e;
}
Expand Down
9 changes: 2 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"noEmit": true
},
"include": ["**/*.test.ts"],
"include": ["**/*.test.ts", "**/*.d.ts"],
"exclude": ["node_modules", "apps/docs/src/**/*.test.ts"]
}