Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

evanlucas
Copy link
Contributor

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.

Ref: #2319

R=@Fishrock123

@thefourtheye thefourtheye added repl Issues and PRs related to the REPL subsystem. test Issues and PRs related to the tests. labels Aug 12, 2015
@evanlucas evanlucas changed the title test: fix race condition in real history test test: fix race condition in repl history test Aug 12, 2015
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`
@cjihrig
Copy link
Contributor

cjihrig commented Aug 12, 2015

LGTM

@Fishrock123
Copy link
Contributor

Interesting, I'll try to take a look into repl about this, nice patch though.

@evanlucas
Copy link
Contributor Author

@silverwind
Copy link
Contributor

@@ -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'
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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..

@Fishrock123
Copy link
Contributor

We could also probably just listen to flushHistory, so long as we don't have a test that does anything after ENTER.

@Fishrock123
Copy link
Contributor

@evanlucas can you see if Fishrock123@9a0fabb fixes it / LGTY?

@evanlucas
Copy link
Contributor Author

I can this evening.

@evanlucas
Copy link
Contributor Author

Closing in favor of #2356

@evanlucas evanlucas closed this Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants