-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: check that modules backed by read-only files can load (win32) #20116
Conversation
|
||
if (process.platform == 'win32') { | ||
// Create readOnlyMod.js and set to read only | ||
const readOnlyMod = fixtures.path('readOnlyMod'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of writing to the fixtures dir, and thus the source tree, can we create this in tmpdir instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the sum total of the change would be:
- require
tmpdir
instead offixtures
- call
tmpdir.refresh()
once - Use
tmpdir.path
instead offixtures.path
cp.execSync(`icacls.exe "${readOnlyModFullPath}" /remove "%USERNAME%" /inheritance:e`); | ||
|
||
// Delete the file | ||
fs.unlinkSync(readOnlyModFullPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(If we use the tmpdir module instead of the fixtures module, then there is no need to unlink.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a change to use tmpdir. I figured cleaning up is safer than having another run try and overwrite the same file (permissions shouldn't conflict as it should be a different tmpdir if under a different account, but just to be safe...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(If you use common/tmpdir
rather than os.tmpdir
, there is no need to clean up because tests are expected to refresh tmpdir before they do anything in it.)
Hi, @billti! Thanks for this! @nodejs/testing PTAL |
I guess @nodejs/platform-windows too... |
Whoops! Not Or look at another test to see some example code: node/test/parallel/test-fs-write-stream-close-without-callback.js Lines 7 to 10 in bf6ce47
|
Hmmm...I think this pull request is against the wrong branch. It should be against |
I switched to the tmpdir requested. I added the test for the v10.x branch as from the linked issue I thought that was what is being targeted ASAP in order to get the 10.0 release done. I can target whatever branch you want though. Just let me know. |
Thank you! node tools/node_modules/eslint/bin/eslint.js test/parallel/test-module-readonly.js Currently, you will get: Some errors:j:\temp\_git\node-fork\test\parallel\1test-module-readonly.js
1:1 error Mandatory module "common" must be loaded node-core/required-modules
1:1 error Use the global form of 'use strict' strict
8:22 error Expected '===' and instead saw '==' eqeqeq
9:1 error Expected indentation of 2 spaces but found 4 indent
10:1 error Expected indentation of 2 spaces but found 4 indent
11:1 error Expected indentation of 2 spaces but found 4 indent
12:1 error Expected indentation of 2 spaces but found 4 indent
12:47 error Strings must use singlequote quotes
13:1 error Expected indentation of 2 spaces but found 4 indent
13:43 error Strings must use singlequote quotes
15:1 error Expected indentation of 2 spaces but found 4 indent
15:1 error Line 15 exceeds the maximum line length of 80 max-len
16:1 error Expected indentation of 2 spaces but found 4 indent
16:1 error Line 16 exceeds the maximum line length of 80 max-len
17:1 error Expected indentation of 2 spaces but found 4 indent
18:1 error Expected indentation of 2 spaces but found 4 indent
20:1 error Expected indentation of 2 spaces but found 4 indent
21:1 error Expected indentation of 2 spaces but found 4 indent
22:1 error Expected indentation of 4 spaces but found 8 indent
23:1 error Expected indentation of 4 spaces but found 8 indent
23:15 error 'mymod' is assigned a value but never used no-unused-vars
24:1 error Expected indentation of 2 spaces but found 4 indent
24:7 error Expected space(s) after "catch" keyword-spacing
25:1 error Expected indentation of 4 spaces but found 8 indent
26:1 error Expected indentation of 2 spaces but found 4 indent
28:1 error Expected indentation of 2 spaces but found 4 indent
29:1 error Expected indentation of 2 spaces but found 4 indent
29:1 error Line 29 exceeds the maximum line length of 80 max-len
31:1 error Expected indentation of 2 spaces but found 4 indent
32:1 error Expected indentation of 2 spaces but found 4 indent
34:1 error Expected indentation of 2 spaces but found 4 indent
34:17 error Use assert.ifError(except) instead node-core/prefer-assert-iferror
✖ 32 problems (32 errors, 0 warnings)
24 errors, 0 warnings potentially fixable with the `--fix` option. About |
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
if (process.platform == 'win32') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common.isWindows
fs.writeFileSync(readOnlyModFullPath, "module.exports = 42;"); | ||
|
||
// Removed any inherited ACEs, and any explicitly granted ACEs for the current user | ||
cp.execSync(`icacls.exe "${readOnlyModFullPath}" /inheritance:r /remove "%USERNAME%"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line here, whitespace/indent errors elsewhere. Can you run make lint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a Windows test the equivalent is vcbuild lint
(or vcbuild lint-js
to just lint the JavaScript files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. We have a guide to writing tests at https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md which explains things like starting the test with require('../common')
.
fs.writeFileSync(readOnlyModFullPath, "module.exports = 42;"); | ||
|
||
// Removed any inherited ACEs, and any explicitly granted ACEs for the current user | ||
cp.execSync(`icacls.exe "${readOnlyModFullPath}" /inheritance:r /remove "%USERNAME%"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a Windows test the equivalent is vcbuild lint
(or vcbuild lint-js
to just lint the JavaScript files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and as has been pointed out by @Trott, please retarget this to the master branch as that's where the libuv fix will go first before being backported into the v10.x branches.
Adding the blocked label as this test is expected to fail (even when the lint issues have been addressed) until we get a libuv with libuv/libuv#1800. |
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
if (process.platform == 'win32') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is currently a Windows only test, you can do:
if (!common.isWindows) {
common.skip('test only runs on Windows');
}
This will skip the test on other platforms and exit the process.
// Delete the file | ||
fs.unlinkSync(readOnlyModFullPath); | ||
|
||
if (except) throw except; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of an if
, we'd ideally want an assertion, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g., assert.ifError(except)
https://nodejs.org/dist/latest-v9.x/docs/api/assert.html#assert_assert_iferror_value
|
(Sorry for all the style nits that are getting picked. We try to put as many of them into the linter as possible rather than having them come up in PR review. Thanks for your patience with it all!) |
No problem. I think I have all the issues addressed. Just trying to run all the tests/linting now. I'll open a new pull request against 'master' when it's ready, and link & close this one when done. |
Opened new pull request against master in #20138 which should address all comments (so far 😉). |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesThis is the test-case for the issue at #20112 . This fails with the issue present, and passes with the fix applied.
Note: Even before any changes,
vcbuild test
gave a ton of failures for me, so not sure if that is my machine or something more fundamental. This test behaves as expected though.CC @vsemozhetbyt, @cjihrig, @richardlau