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

feat: add ability to reject connection with ECONNREFUSED #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

viglucci
Copy link

@viglucci viglucci commented Aug 2, 2021

Addresses #72

For context -- I am looking to use this functionality in the tests for rsocket-js.

Usage example:

it("rejects if the connection errors", async () => {
  // arrange
  mitm.on("connect", function (socket) {
    socket.reject();
  });

  const expectedError = new Error();
  expectedError.address = "127.0.0.1";
  expectedError.code = "ECONNREFUSED";
  expectedError.errno = -4078;
  expectedError.port = 9090;
  expectedError.syscall = "connect";

  // act
  const transport = new TcpClientTransport({
    connectionOptions: {
      host: "localhost",
      port: 9090,
    },
  });

  // assert
  await expect(transport.connect()).rejects.toEqual(expectedError);
});

index.js Outdated Show resolved Hide resolved
@vkruoso
Copy link

vkruoso commented Nov 30, 2021

This would be really great to test edge cases. This happens in real life and it is hard to test it.

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.

2 participants