-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: fix race condition in repl history test #2358
Conversation
Previously, there were cases when the `end` event could be emitted before the `flushHistory` event. This change makes the next test fire off after the specified event based on the `test`
96dd3b9
to
44e8c4b
Compare
LGTM |
Interesting, I'll try to take a look into repl about this, nice patch though. |
@@ -74,35 +74,41 @@ const oldHistoryPath = path.join(fixtures, 'old-repl-history-file.json'); | |||
const tests = [{ | |||
env: { NODE_REPL_HISTORY: '' }, | |||
test: [UP], | |||
expected: [prompt, replDisabled, prompt] | |||
expected: [prompt, replDisabled, prompt], | |||
event: 'end' |
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.
Are you sure this works? I don't think the repl actually emits this at all. Console.log something in on('close',...)
/ on(opts.event,...)
and make sure it calls the same number as the number of tests.
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.
Alternatively, use this patch, which I am adding to #2356:
diff --git a/test/sequential/test-repl-persistent-history.js b/test/sequential/test-repl-persistent-history.js
index 8d550f6..27aca28 100644
--- a/test/sequential/test-repl-persistent-history.js
+++ b/test/sequential/test-repl-persistent-history.js
@@ -144,6 +144,13 @@ const tests = [{
}];
+var testsNotRan = tests.length;
+
+process.on('beforeExit', function() {
+ assert.strictEqual(testsNotRan, 0);
+});
+
+
// Copy our fixture to the tmp directory
fs.createReadStream(historyFixturePath)
.pipe(fs.createWriteStream(historyPath)).on('unpipe', runTest);
@@ -185,6 +192,7 @@ function runTest() {
repl.on('close', function() {
// Ensure everything that we expected was output
assert.strictEqual(expected.length, 0);
+ testsNotRan--;
setImmediate(runTest);
});
EDIT: FIXED
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.
The end event worked fine for me. To really see it, you can run with the NODE_DEBUG=repl
. It makes me wonder if we should defer emitting close until after flushHistory though?
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.
It makes me wonder if we should defer emitting close until after flushHistory though?
That's what I was thinking.
I can't find where the 'end' event is emitted on the repl/readline though..
We could also probably just listen to |
@evanlucas can you see if Fishrock123@9a0fabb fixes it / LGTY? |
I can this evening. |
Closing in favor of #2356 |
Previously, there were cases when the
end
event could be emittedbefore the
flushHistory
event. This change makes the next test fireoff after the specified event based on the
test
.Ref: #2319
R=@Fishrock123