test: fix race condition in repl history test#2358
test: fix race condition in repl history test#2358evanlucas wants to merge 1 commit intonodejs:masterfrom
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. |
There was a problem hiding this comment.
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.
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.
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.
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
endevent could be emittedbefore the
flushHistoryevent. This change makes the next test fireoff after the specified event based on the
test.Ref: #2319
R=@Fishrock123