-
-
Notifications
You must be signed in to change notification settings - Fork 35k
test: reduce flakiness of test-fs-read-position-validation.mjs
#42999
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
Merged
nodejs-github-bot
merged 9 commits into
nodejs:master
from
LiviaMedeiros:fs-reads-position-test-segregate
May 15, 2022
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fe48cc5
test: reduce flakiness of `test-fs-read-position-validation.mjs`
LiviaMedeiros 21a0db5
squash: adjust promisification
LiviaMedeiros e2c07c9
squash: fix typo
LiviaMedeiros d9a88ba
squash: the actual fix: do not close file too early
LiviaMedeiros 90e5cd7
squash: refactor callbacks, add test for buffer[, options]
LiviaMedeiros 45b3626
squash: refactor promisification
LiviaMedeiros c85e84d
squash: add explicit async
LiviaMedeiros f114cbb
squash: reject on errors
LiviaMedeiros 11a5b35
squash: fix race condition on closing fd
LiviaMedeiros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
test: reduce flakiness of
test-fs-read-position-validation.mjs
- Loading branch information
commit fe48cc5321ce29366a9061369fe42d3f3b83cea4
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,80 @@ | ||
| import '../common/index.mjs'; | ||
| import * as fixtures from '../common/fixtures.mjs'; | ||
| import fs from 'fs'; | ||
| import assert from 'assert'; | ||
|
|
||
| // This test ensures that "position" argument is correctly validated | ||
|
|
||
| const filepath = fixtures.path('x.txt'); | ||
|
|
||
| const buffer = Buffer.from('xyz\n'); | ||
| const offset = 0; | ||
| const length = buffer.byteLength; | ||
|
|
||
| // allowedErrors is an array of acceptable internal errors | ||
| // For example, on some platforms read syscall might return -EFBIG | ||
| function testValid(position, allowedErrors = []) { | ||
| let fdSync; | ||
| try { | ||
| fdSync = fs.openSync(filepath, 'r'); | ||
| fs.readSync(fdSync, buffer, offset, length, position); | ||
| fs.readSync(fdSync, buffer, { offset, length, position }); | ||
| } catch (err) { | ||
| if (!allowedErrors.includes(err.code)) { | ||
| assert.fail(err); | ||
| } | ||
| } finally { | ||
| if (fdSync) fs.closeSync(fdSync); | ||
| } | ||
| } | ||
|
|
||
| function testInvalid(code, position, internalCatch = false) { | ||
| let fdSync; | ||
| try { | ||
| fdSync = fs.openSync(filepath, 'r'); | ||
| assert.throws( | ||
| () => fs.readSync(fdSync, buffer, offset, length, position), | ||
| { code } | ||
| ); | ||
| assert.throws( | ||
| () => fs.readSync(fdSync, buffer, { offset, length, position }), | ||
| { code } | ||
| ); | ||
| } finally { | ||
| if (fdSync) fs.closeSync(fdSync); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| testValid(undefined); | ||
| testValid(null); | ||
| testValid(-1); | ||
| testValid(-1n); | ||
|
|
||
| testValid(0); | ||
| testValid(0n); | ||
| testValid(1); | ||
| testValid(1n); | ||
| testValid(9); | ||
| testValid(9n); | ||
| testValid(Number.MAX_SAFE_INTEGER, [ 'EFBIG' ]); | ||
|
|
||
| testValid(2n ** 63n - 1n - BigInt(length), [ 'EFBIG' ]); | ||
| testInvalid('ERR_OUT_OF_RANGE', 2n ** 63n); | ||
|
|
||
| // TODO(LiviaMedeiros): test `2n ** 63n - BigInt(length)` | ||
|
|
||
| testInvalid('ERR_OUT_OF_RANGE', NaN); | ||
| testInvalid('ERR_OUT_OF_RANGE', -Infinity); | ||
| testInvalid('ERR_OUT_OF_RANGE', Infinity); | ||
| testInvalid('ERR_OUT_OF_RANGE', -0.999); | ||
| testInvalid('ERR_OUT_OF_RANGE', -(2n ** 64n)); | ||
| testInvalid('ERR_OUT_OF_RANGE', Number.MAX_SAFE_INTEGER + 1); | ||
| testInvalid('ERR_OUT_OF_RANGE', Number.MAX_VALUE); | ||
|
|
||
| for (const badTypeValue of [ | ||
| false, true, '1', Symbol(1), {}, [], () => {}, Promise.resolve(1), | ||
| ]) { | ||
| testInvalid('ERR_INVALID_ARG_TYPE', badTypeValue); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.