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

test: reduce test-debugger-heap-profiler duration #54843

Closed
wants to merge 1 commit into from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Sep 7, 2024

Reduces the filesystem operations done on test-debugger-heap-profiler test. I didn't understand why we called JSON.parse(readfileSync) in the first place.

node test/parallel/test-debugger-heap-profiler.js 
> 0.13s user 0.03s system 49% cpu 0.319 total

@anonrig anonrig requested a review from jasnell September 7, 2024 22:38
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Sep 7, 2024
@avivkeller
Copy link
Member

For refrence, before this change, I was getting:

$ time node test/parallel/test-debugger-heap-profiler.js 

real    0.53s
user    0.11s
sys     0.08s
cpu     34%

@@ -23,11 +24,11 @@ const filename = tmpdir.resolve('node.heapsnapshot');
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('takeHeapSnapshot()');
JSON.parse(readFileSync(filename, 'utf8'));
assert.ok(fs.existsSync(filename));
Copy link
Member

@avivkeller avivkeller Sep 7, 2024

Choose a reason for hiding this comment

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

Does this change the test? The original test would've thrown an error if the file wasn't valid JSON.

Copy link
Member Author

Choose a reason for hiding this comment

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

other tests are already covers that. i don't think this is needed.

Copy link
Member

@lpinca lpinca Sep 8, 2024

Choose a reason for hiding this comment

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

This test is used as a regression test for a write race condition so checking for valid JSON makes sense. See 16a9ab1.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. It appears that this test timeouts pretty often. Any recommendation on how to avoid?

Copy link
Member

@avivkeller avivkeller Sep 8, 2024

Choose a reason for hiding this comment

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

You could still (maybe) reduce the operation count by not reading the file to a string. JSON.parse accepts a buffer as input.

Copy link

codecov bot commented Sep 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.62%. Comparing base (38974a2) to head (53d04d3).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #54843      +/-   ##
==========================================
+ Coverage   87.61%   87.62%   +0.01%     
==========================================
  Files         651      651              
  Lines      183343   183343              
  Branches    35441    35450       +9     
==========================================
+ Hits       160641   160661      +20     
+ Misses      15958    15946      -12     
+ Partials     6744     6736       -8     

see 31 files with indirect coverage changes

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 8, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 8, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

as @lpinca noted

@@ -23,11 +24,11 @@ const filename = tmpdir.resolve('node.heapsnapshot');
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('takeHeapSnapshot()');
JSON.parse(readFileSync(filename, 'utf8'));
assert.ok(fs.existsSync(filename));
Copy link
Member

@avivkeller avivkeller Sep 8, 2024

Choose a reason for hiding this comment

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

Suggested change
assert.ok(fs.existsSync(filename));
JSON.parse(fs.readFileSync(filename));

This way, the JSON is still being parsed, but FS isn't reading the file to a string

Copy link
Member

Choose a reason for hiding this comment

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

It does not change anything. toString() is called on the input.

// Check that two simultaneous snapshots don't step all over each other.
// Refs: https://github.com/nodejs/node/issues/39555
await cli.command('takeHeapSnapshot(); takeHeapSnapshot()');
JSON.parse(readFileSync(filename, 'utf8'));
assert.ok(fs.existsSync(filename));
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@anonrig anonrig closed this Sep 8, 2024
@anonrig anonrig deleted the improve-heap-profiler branch September 8, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants