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(attach): improve disconnect test #414

Merged
merged 4 commits into from
Oct 11, 2024
Merged

Conversation

gjf7
Copy link
Contributor

@gjf7 gjf7 commented Oct 11, 2024

Closes #314.

Problem:

This test may time out, because the proc.on('close') event is never triggered.

FAIL src/attach/attach.test.ts (5.62 s)
  ● Nvim API › emits "disconnect" after quit
    thrown: "Exceeded timeout of 5000 ms for a test while waiting for `done()` to be called.

      |   });
      |
    > |   it('emits "disconnect" after quit', done => {
      |   ^
      |     const disconnectMock = jest.fn();
      |     nvim.on('disconnect', disconnectMock);
      |     nvim.quit();

      at it (src/attach/attach.test.ts:138:3)
      at Object.describe (src/attach/attach.test.ts:6:1)

Solution:

Listen for 'exit' instead of 'close'. This may indicate that Nvim or node-client
is not properly closing all of its streams, but that is unrelated to this
particular test.

@gjf7 gjf7 marked this pull request as draft October 11, 2024 06:44
nvim.quit();

proc.on('close', () => {
expect(disconnectMock.mock.calls.length).toBe(1);
expect(disconnectCalled).toBe(true);
done();
Copy link
Member

@justinmk justinmk Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the test is timing out, that means this done is not called, which means the 'close' event isn't emitted (or stuff is getting disposed before handling the emitted 'close' event).

This proc.on was added in c9a3dd0 for some reason. But later the proc.kill call was removed, so whatever reason that proc.on was added no longer exists.

we should just restore the old logic, which simply did nvim.on('disconnect', done);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I understand that, but how race could happen to cause this problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the disconnect call on proc ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, that causes the test harness (jest) to kill Nvim too early, which then raises EPIPE because Nvim still has messages to process.

@gjf7
Copy link
Contributor Author

gjf7 commented Oct 11, 2024

Oops, failed again, so the mock function indeed not the issue here.

nvim.on('disconnect', () => {
called = true;
});

nvim.quit();

proc.on('close', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on local runs, changing this to 'exit' seems more reliable. It's strange that 'close' is sometimes not emitted, but that was never the purpose of this test...

Suggested change
proc.on('close', () => {
proc.on('exit', () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, we only want make sure disconnect is called.

@gjf7 gjf7 marked this pull request as ready for review October 11, 2024 08:54
@gjf7
Copy link
Contributor Author

gjf7 commented Oct 11, 2024

We can run CI a few more times to see if it's working.

@gjf7
Copy link
Contributor Author

gjf7 commented Oct 11, 2024

Looks like it happens on windows. see nodejs/node#4500

@justinmk
Copy link
Member

CI has been green 10+ times 🎉

Looks like it happens on windows. see nodejs/node#4500

#314 happens on all platforms. Based on some local testing, it looks like stderr is not closed, and that would be why 'close' event does not emit. This may indicate a bug in node-client or Nvim.

@justinmk justinmk merged commit 0909033 into neovim:master Oct 11, 2024
10 checks passed
@gjf7
Copy link
Contributor Author

gjf7 commented Oct 11, 2024

@justinmk Thanks for your guide!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unreliable test: emits "disconnect" after quit
2 participants