Skip to content

test: do not write fixture in test-require-symlink - #15067

Closed
Trott wants to merge 1 commit into
nodejs:masterfrom
Trott:vacay-1
Closed

test: do not write fixture in test-require-symlink#15067
Trott wants to merge 1 commit into
nodejs:masterfrom
Trott:vacay-1

Conversation

@Trott

Copy link
Copy Markdown
Member

test-require-symlink modifies the fixture directory by adding a symlink.
Copy the fixture to the test tmpdir instead of modifying the fixture
directory.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test module

@TrottTrott added module Issues and PRs related to the module subsystem. test Issues and PRs related to the tests. labels Aug 28, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo: fixtureSource

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be dirName or tmpDirTarget.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be dirName or tmpDirTarget.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be dirName or tmpDirTarget.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't you rather execSync('cp -Rf Src Trg') / for windows execSync('xcopy /E /Y Src Trg')?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I prefer the more verbose way here because:

  • there's no difference between Windows and POSIX test code that way
  • it does not depend on even the most mundane external dependency.

execSync always feels like a code smell to me, although it's almost certainly not going to cause problems here.

I admit my reasons are not super-compelling but I'm also not sure the counter-arguments are super-compelling either. I'll certainly change it if this is a blocking objection. :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not too thrilled about this (I know it was like this before). I rather have an emperical test:

constsymLinkTest=path.join(common.tmpDir,'symLinkTest .js');try{fs.symlinkSync(__filename,symLinkTest);}catch(e){assert.strictEqual(e.code,'EPERM');common.skip('insufficient privileges');}

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Sure, done! (I changed the assert to an if ... throw.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this need to be tested upfront as opposed to wrapping the actual symlink calls in the test in a try-catch block?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Hmmm...maybe even better: It looks like there's a common.canCreateSymlink() used in two files. I can use it here.

@Trott
Trottforce-pushed the vacay-1 branch 2 times, most recently from fea8367 to b49c223CompareAugust 30, 2017 05:37

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can now be fs.copyFileSync().

@BridgeAR

Copy link
Copy Markdown
Member

Ping @Trott

@Trott
Trottforce-pushed the vacay-1 branch 2 times, most recently from 4383a34 to 3f1c2deCompareSeptember 13, 2017 21:35
@Trott

Copy link
Copy Markdown
MemberAuthor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this need to be tested upfront as opposed to wrapping the actual symlink calls in the test in a try-catch block?

@Trott
Trottforce-pushed the vacay-1 branch 2 times, most recently from 6443815 to 59f37e4CompareSeptember 14, 2017 14:44
@Trott

Copy link
Copy Markdown
MemberAuthor

@refack Is this OK by you as is, or do you object? If you want changes, can you clarify what changes you'd like to see?

@refack

Copy link
Copy Markdown
Contributor

@refack Is this OK by you as is, or do you object? If you want changes, can you clarify what changes you'd like to see?

  • common.canCreateSymlink() ✔️ WinWin
  • copyDir(source, target) ✔️ I yield to OP

@refack

Copy link
Copy Markdown
Contributor

New CI (so this could land as soon as): https://ci.nodejs.org/job/node-test-pull-request/10092/

@jasnell

Copy link
Copy Markdown
Member

This failed CI across the board:

not ok 1238 parallel/test-require-symlink
---
duration_ms: 0.532
severity: fail
stack: |-
assert.js:43
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: 1 === 0
at ChildProcess.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/centos5-32/test/parallel/test-require-symlink.js:79:12)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:944:16)
at Socket.stream.socket.on (internal/child_process.js:364:11)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at Pipe._handle.close [as _onclose] (net.js:551:12)

@Trott

Copy link
Copy Markdown
MemberAuthor

Hmmm...passing for me locally. But obviously not in CI.... will take a look...

@Trott

Copy link
Copy Markdown
MemberAuthor

Odd. When I log in to a CI machine where it's failing and run the test from the CLI there, it works fine.

@refack

Copy link
Copy Markdown
Contributor

su iojs?

@Trott

Copy link
Copy Markdown
MemberAuthor

@refack Tried both sudo -u iojs a and su - iojs and in both cases, the test still ran fine. 🤔

@Trott

Trott commented Sep 15, 2017

Copy link
Copy Markdown
MemberAuthor

I added some logging of the error in CI and it seems like linkscript.js can't find ../../common.js but only when it is run from CI.

'module.js:505
throw err;
^
Error: Cannot find module '../../common'
at Function.Module._resolveFilename (module.js:503:15)
at Function.Module._load (module.js:452:23)
at Module.require (module.js:544:17) at require (internal/module.js:11:18)
at Object.<anonymous> (/data/iojs/node-tmp/tmp.2/module-require-symlink/symlinked.js:2:16)
at Module._compile (module.js:600:30)
at Object.Module._extensions..js (module.js:611:10)
at Module.load (module.js:521:32)
at tryModuleLoad (module.js:484:12)
at Function.Module._load (module.js:476:3)

@Trott

Copy link
Copy Markdown
MemberAuthor

Ah! Looks like symlinking with a full path messes things up because of a symlink higher up in the path. The tmp directories in test are symlinked to /data/iojs/node-tmp and this is no doubt a common pattern in CI (as evidenced by across-the-board failure).

I'll fix the test to use relative paths for symlinking all within the tmp dir.

@Trott

Copy link
Copy Markdown
MemberAuthor

OK, hopefully that fixes it...

CI: https://ci.nodejs.org/job/node-test-pull-request/10105/

@Trott

Copy link
Copy Markdown
MemberAuthor

Cleaned up the test but missed cleaning up the fixture which still refers to the full path of the tmp directory...

test-require-symlink modifies the fixture directory by adding a symlink.
Copy the fixture to the test tmpdir instead of modifying the fixture
directory.
This also uses a more empirical test for checking for the ability to
make symlinks on Windows.
@Trott

Trott commented Sep 16, 2017

Copy link
Copy Markdown
MemberAuthor

@Trott

Copy link
Copy Markdown
MemberAuthor

OK, results look much better that time, but a few infra-related issues, some of which are now fixed, so one more time...

CI: https://ci.nodejs.org/job/node-test-pull-request/10109/

@BridgeAR

Copy link
Copy Markdown
Member

@Trott the CI seems fine (the linter is failing often... I do not know why but maybe a eslint update might help - or does someone know where the errors might come from?). Is this ready to land?

Trott added a commit to Trott/io.js that referenced this pull request Sep 19, 2017
test-require-symlink modifies the fixture directory by adding a symlink.
Copy the fixture to the test tmpdir instead of modifying the fixture
directory.
This also uses a more empirical test for checking for the ability to
make symlinks on Windows.
PR-URL: nodejs#15067
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott

Copy link
Copy Markdown
MemberAuthor

Landed in 6f34076

@TrottTrott closed this Sep 19, 2017
jasnell pushed a commit that referenced this pull request Sep 20, 2017
test-require-symlink modifies the fixture directory by adding a symlink.
Copy the fixture to the test tmpdir instead of modifying the fixture
directory.
This also uses a more empirical test for checking for the ability to
make symlinks on Windows.
PR-URL: #15067
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
test-require-symlink modifies the fixture directory by adding a symlink.
Copy the fixture to the test tmpdir instead of modifying the fixture
directory.
This also uses a more empirical test for checking for the ability to
make symlinks on Windows.
PR-URL: nodejs/node#15067
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
test-require-symlink modifies the fixture directory by adding a symlink.
Copy the fixture to the test tmpdir instead of modifying the fixture
directory.
This also uses a more empirical test for checking for the ability to
make symlinks on Windows.
PR-URL: nodejs/node#15067
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins

Copy link
Copy Markdown
Contributor

This does not land cleanly in LTS. Please feel free to manually backport by following the guide. Please also feel free to replace do-not-land if it is being backported

@Trott
Trott deleted the vacay-1 branch January 13, 2022 22:46
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

moduleIssues and PRs related to the module subsystem.testIssues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@Trott@BridgeAR@refack@jasnell@MylesBorins@richardlau