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: verification of fuel-core node killing #2759

Merged
merged 7 commits into from
Jul 18, 2024
Merged

Conversation

nedsalk
Copy link
Contributor

@nedsalk nedsalk commented Jul 12, 2024

Summary

This PR addresses the issue reported in #1755 (comment).

I have removed the flaky test and opted for verifying the logic via mocks. I have verified that spawning a fuel-core process group with the detached:true argument and killing the process group via process.kill(-child.pid) works and the mocks are verifying that the code is doing that.
I initially wanted to ensure that all fuel-core nodes are killed in the tests-ci.sh script by verifying that no fuel-core processes are running after pnpm test is run, but the team suggested this approach as being enough and that this external checking is not necessary.

Checklist

  • I addedtests to prove my changes
  • I updated — all the necessary docs
  • I reviewed — the entire PR myself, using the GitHub UI
  • I described — all breaking changes and the Migration Guide

@nedsalk nedsalk added the bug Issue is a bug label Jul 12, 2024
@nedsalk nedsalk self-assigned this Jul 12, 2024
@nedsalk nedsalk added this to the 0.x mainnet milestone Jul 12, 2024
@nedsalk nedsalk enabled auto-merge (squash) July 12, 2024 09:18
@nedsalk nedsalk mentioned this pull request Jul 12, 2024
4 tasks
danielbate

This comment was marked as outdated.

@nedsalk

This comment was marked as outdated.

@nedsalk nedsalk requested a review from danielbate July 12, 2024 10:16
@petertonysmith94

This comment was marked as outdated.

@nedsalk

This comment was marked as outdated.

@Torres-ssf

This comment was marked as outdated.

@Torres-ssf

This comment was marked as outdated.

@arboleya
Copy link
Member

[..] but why does only this test suite require the await sleep(1000)?

Yes, I second this.

I am always hesitant about fixing flakiness with timeouts because the latter is usually the cause of the former.

Timeouts often seem like a quick symptomatic solution to a potentially unclear underlying cause.

Copy link
Contributor

@danielbate danielbate left a comment

Choose a reason for hiding this comment

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

@nedsalk thinking out loud here, could block scoping inside the test have a better desired effect, given that using the hook seems to be flaky and that is the expected usage of the disosable.

  test('synchronous cleanup kills node before test runner exits', async () => {
    const killedNode = {
      url: '',
    };

    {
      const { cleanup, url } = await launchNode({ loggingEnabled: false });
      killedNode.url = url;
      cleanup();
    }

    await expect(fetch(killedNode.url)).rejects.toThrow('fetch failed');
  });

@nedsalk nedsalk disabled auto-merge July 13, 2024 13:18
@nedsalk nedsalk changed the title fix: flaky launchNode-singular-test.test.ts fix: verification of all test nodes being killed Jul 15, 2024
@nedsalk nedsalk marked this pull request as draft July 15, 2024 10:25
@nedsalk
Copy link
Contributor Author

nedsalk commented Jul 15, 2024

@FuelLabs/sdk-ts I have approached this problem from a different angle and explained my reasoning in the PR's description.

@nedsalk
Copy link
Contributor Author

nedsalk commented Jul 15, 2024

@danielbate The problem is that cleanup is synchronous whereas process killing is by it's nature asynchronous because it's done by the OS. The only 100% bulletproof way to ensure that after cleanup is called the node is killed is to make cleanup asynchronous and await some OS signal. I opted out of that because it would force us to use the async disposable pattern as explained here, which is IMO prohibitive for the DX:

using launched = await launchTestNode();
// vs
await using launched = await launchTestNode();

@nedsalk nedsalk requested a review from danielbate July 15, 2024 11:00
maschad
maschad previously approved these changes Jul 17, 2024
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

Nice job

Copy link

vercel bot commented Jul 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-ts ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2024 1:33pm

danielbate
danielbate previously approved these changes Jul 18, 2024
Copy link
Contributor

@danielbate danielbate left a comment

Choose a reason for hiding this comment

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

Much better than await using ...

arboleya
arboleya previously approved these changes Jul 18, 2024
packages/account/src/test-utils/launchNode.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
79.37%(+0%) 71.65%(+0%) 77.3%(+0%) 79.5%(+0%)
Changed Files:

Coverage values did not change👌.

@nedsalk nedsalk merged commit 98748ec into master Jul 18, 2024
21 checks passed
@nedsalk nedsalk deleted the ns/fix/flaky-test branch July 18, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants