-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
repl: limit line processing to one at a time #39392
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
Open
ejose19
wants to merge
10
commits into
nodejs:main
Choose a base branch
from
ejose19:ej/replEvalPause
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7ad5ca4
repl: limit line processing to one at a time
ejose19 b77043c
repl: change IIFE to single iteration loop
ejose19 65ab582
repl: adjust autolibs test
ejose19 4074c38
repl: fix line-queue tests
ejose19 569eb68
repl: improve line queue tests
ejose19 10dc12a
repl: improve queue debug messages
ejose19 6b11537
repl: improve eval doc entry
ejose19 7727100
repl: apply eslint fixes
ejose19 4cb5215
Update test/parallel/test-repl-line-queue.js
ejose19 d2dcacd
Update test/parallel/test-repl-line-queue.js
ejose19 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
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
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
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,130 @@ | ||
'use strict'; | ||
// Flags: --expose-internals --experimental-repl-await | ||
|
||
require('../common'); | ||
const ArrayStream = require('../common/arraystream'); | ||
|
||
const assert = require('assert'); | ||
|
||
function* expectedLines(lines) { | ||
yield* lines; | ||
} | ||
|
||
const expectedDebug = expectedLines([ | ||
[ | ||
'line %j', | ||
'const x = await new Promise((r) => setTimeout(() => r(1), 500));', | ||
], | ||
[ | ||
'eval %j', | ||
'const x = await new Promise((r) => setTimeout(() => r(1), 500));\n', | ||
], | ||
['queuing line %j', 'x;'], | ||
['finish', null, undefined], | ||
['queued line %j', 'x;'], | ||
['eval %j', 'x;\n'], | ||
['finish', null, 1], | ||
['line %j', 'const y = 3;'], | ||
['eval %j', 'const y = 3;\n'], | ||
['finish', null, undefined], | ||
['line %j', 'x + y;'], | ||
['eval %j', 'x + y;\n'], | ||
['finish', null, 4], | ||
['line %j', 'const z = 4;'], | ||
['eval %j', 'const z = 4;\n'], | ||
['finish', null, undefined], | ||
['queuing line %j', 'z + 1'], | ||
['queued line %j', 'z + 1'], | ||
['eval %j', 'z + 1\n'], | ||
['finish', null, 5], | ||
]); | ||
|
||
let calledDebug = false; | ||
require('internal/util/debuglog').debuglog = () => { | ||
return (...args) => { | ||
calledDebug = true; | ||
assert.deepStrictEqual(args, expectedDebug.next().value); | ||
}; | ||
}; | ||
|
||
// Import `repl` after replacing original `debuglog` | ||
const repl = require('repl'); | ||
|
||
const putIn = new ArrayStream(); | ||
repl.start({ | ||
input: putIn, | ||
output: putIn, | ||
useGlobal: false, | ||
}); | ||
|
||
const expectedOutput = expectedLines([ | ||
'undefined\n', | ||
'> ', | ||
'1\n', | ||
'> ', | ||
'undefined\n', | ||
'> ', | ||
'4\n', | ||
'> ', | ||
'undefined\n', | ||
'> ', | ||
'5\n', | ||
'> ', | ||
]); | ||
|
||
let calledOutput = false; | ||
function writeCallback(data) { | ||
calledOutput = true; | ||
assert.strictEqual(data, expectedOutput.next().value); | ||
} | ||
|
||
putIn.write = writeCallback; | ||
|
||
function clearCalled() { | ||
calledDebug = false; | ||
calledOutput = false; | ||
} | ||
|
||
// Lines sent after an async command that hasn't finished | ||
// in the same write are enqueued | ||
function test1() { | ||
putIn.run([ | ||
'const x = await new Promise((r) => setTimeout(() => r(1), 500));\nx;', | ||
]); | ||
assert(calledDebug); | ||
|
||
setTimeout(() => { | ||
assert(calledOutput); | ||
clearCalled(); | ||
|
||
test2(); | ||
}, 1000); | ||
} | ||
|
||
// Lines sent after a sync command in the same write are not enqueued | ||
function test2() { | ||
putIn.run(['const y = 3;\nx + y;']); | ||
|
||
assert(calledDebug); | ||
assert(calledOutput); | ||
clearCalled(); | ||
|
||
test3(); | ||
} | ||
|
||
// Lines sent during an output write event of a previous command | ||
// are enqueued | ||
function test3() { | ||
putIn.write = (data) => { | ||
writeCallback(data); | ||
putIn.write = writeCallback; | ||
putIn.run(['z + 1']); | ||
}; | ||
|
||
putIn.run(['const z = 4;']); | ||
|
||
assert(calledDebug); | ||
assert(calledOutput); | ||
} | ||
|
||
test1(); |
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.