-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix root-ownership race conditions in meta-test
Currently all of our tests verify on teardown that there are no root-owned files in the cache. However, owing to some race conditions and slippery stream event deferral behavior that won't be fixed until v7, occasionally cacache's chown doesn't get processed until _after_ the promise resolves and the test ends. As a result, sometimes this check occurs before the chown has happened, resulting in flaky hard-to-reproduce failures. The somewhat-kludgey solution here is to move the ownership check from t.teardown to process.on('exit'). In npm v7, we should move it back to t.teardown, because we should never have a test that resolves in such a way as to leave the cache in an invalid state. PR-URL: #262 Credit: @isaacs Close: #262 Reviewed-by: @isaacs
- Loading branch information
Showing
2 changed files
with
43 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const t = require('tap') | ||
if (!process.getuid || process.getuid() !== 0 || !process.env.SUDO_UID || !process.env.SUDO_GID) { | ||
t.pass('this test only runs in sudo mode') | ||
t.end() | ||
process.exit(0) | ||
} | ||
|
||
const common = require('../common-tap.js') | ||
const fs = require('fs') | ||
const mkdirp = require('mkdirp') | ||
mkdirp.sync(common.cache + '/root/owned') | ||
fs.writeFileSync(common.cache + '/root/owned/file.txt', 'should be chowned') | ||
const chown = require('chownr') | ||
|
||
// this will fire after t.teardown() but before process.on('exit') | ||
setTimeout(() => { | ||
chown.sync(common.cache, +process.env.SUDO_UID, +process.env.SUDO_GID) | ||
}, 100) | ||
|
||
t.pass('this is fine') |