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: fix failure in test/sequential/test-heapdump.js #41772

Conversation

RaisinTen
Copy link
Contributor

The test was failing when it was being run with superuser privileges,
so this changes the test from attempting to write to a read-only file to
attempting to write to a file with the same name as that of an existing
directory, as that is a more reliable way of making
v8.writeHeapSnapshot() throw even when run with sudo.

Fixes: #41643
Signed-off-by: Darshan Sen [email protected]

The test was failing when it was being run with superuser privileges,
so this changes the test from attempting to write to a read-only file to
attempting to write to a file with the same name as that of an existing
directory, as that is a more reliable way of making
v8.writeHeapSnapshot() throw even when run with sudo.

Fixes: nodejs#41643
Signed-off-by: Darshan Sen <[email protected]>
@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 Jan 30, 2022
@nodejs-github-bot

This comment has been minimized.

@Trott
Copy link
Member

Trott commented Jan 30, 2022

Looks like maybe this change makes it fail on Windows?

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Shouldn't the directory be deleted at the end of the test?

@Trott
Copy link
Member

Trott commented Jan 30, 2022

Shouldn't the directory be deleted at the end of the test?

Because we're in a test tmpdir and those are all cleaned up by test.py, it's not strictly necessary and we don't do that in most tests. We do make an exception for large files and try to clean those up.

@nodejs-github-bot

This comment has been minimized.

@RaisinTen
Copy link
Contributor Author

Looks like maybe this change makes it fail on Windows?

@Trott yes that happens because the writeHeapSnapshot() implementation uses things like fopen() instead of uv_fs_open() underneath. Added a TODO.

const readonlyFile = 'ro';
fs.writeFileSync(readonlyFile, Buffer.alloc(0), { mode: 0o444 });
const directory = 'directory';
fs.mkdirSync(directory);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this change will keep the test content as same as before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mawaregetsuka Yes but the intention is still the same. If you go through the PR description where this was introduced - #41373, it mentions:

this PR makes v8.writeHeapSnapshot throw if the file could not be written

So the current test still attempts to recreate a scenario where the function won't be able to write to the file, so we expect it to throw.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, now I understand. That's a clever solution

@nodejs-github-bot

This comment was marked as outdated.

@Trott
Copy link
Member

Trott commented Feb 1, 2022

@nodejs/testing

@RaisinTen
Copy link
Contributor Author

Can this get a review please?

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Mar 12, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 12, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 14, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 14, 2022
@nodejs-github-bot nodejs-github-bot merged commit 82181bb into nodejs:master Mar 14, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 82181bb

@RaisinTen RaisinTen deleted the test/fix-failure-in-test/sequential/test-heapdump.js-when-run-with-sudo branch March 15, 2022 01:01
@RaisinTen RaisinTen removed the review wanted PRs that need reviews. label Mar 20, 2022
@bengl
Copy link
Member

bengl commented Mar 21, 2022

This doesn't land on 17.x, and it looks like it's because it's modifying code added in a semver-major, so I'm adding the dont-land-on-17 label. Please comment if you think it should land.

xtx1130 pushed a commit to xtx1130/node that referenced this pull request Apr 25, 2022
The test was failing when it was being run with superuser privileges,
so this changes the test from attempting to write to a read-only file to
attempting to write to a file with the same name as that of an existing
directory, as that is a more reliable way of making
v8.writeHeapSnapshot() throw even when run with sudo.

Fixes: nodejs#41643
Signed-off-by: Darshan Sen <[email protected]>

PR-URL: nodejs#41772
Reviewed-By: Antoine du Hamel <[email protected]>
@juanarbol
Copy link
Member

This depends on #41373, which can not be included in v16.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. 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.

test/sequential/test-heapdump.js lines 27 through 39 is bound to fail
7 participants