abelljs/abell

Unit tests fail when port 5000 is occupied

abhijit-hota opened this issue · 6 comments

Describe the bug
Unit tests fail when there is an application running on port 5000.

npm test and npm run test:unit fail when there is an application running on 5000.

To Reproduce

  • Start a process in Port 5000.
  • Run npm test or npm run test:unit
  • The tests fail.

Expected behavior
The server should listen to the next ports.

Screenshots
For npm test

image
image

npm run test:unit also gives the same result: https://pastebin.com/ricHw8ug .

Specs:

  • Abell Version: 0.6.4
  • Node Version: 12.18.0
  • Operating System: Windows 10 Home

This is kind of expected as the test script tries to bind to that port 5000 so that we can test the retry logic of the dev server:

const dummyServer = net.createServer();
dummyServer.listen(SERVER_DEFAULT_PORT);
// SERVER_DEFAULT_PORT is 5000

I don't think we should add a retry logic for something that tests retrying logic. In CI this passes as port 5000 is not occupied.

There is also no other way of testing a retrying logic without acquiring the default ports programatically.

I will suggest you should close the process which is occupying the port.

The actual dev server already listens on the next port. If you want to run the dev server while also running the unit tests, just run the app on port 5005 using the -p flag. Or you can skip these tests while developing

Only thing that we can do but I would say would be an ugly hack is to catch port acquisition error and skip the server initialisation on the test scripts that is used to acquire the port. But that might reduce the reliability of this test.

This is kind of expected as the test script tries to bind to that port 5000 so that we can test the retry logic of the dev server

But there is a test for this, isn't it? Maybe rewrite the tests in a way that passes for this case too.
I don't know much about testing but if it is "expected to fail", then shouldn't those cases be considered?

The actual dev server already listens on the next port. If you want to run the dev server while also running the unit tests, just run the app on port 5005 using the -p flag

Noted. Thanks!

Yeah I think as @pantharshit00 said, it is fine if it breaks locally the tests will pass CI anyway and to make them pass locally, we can use abell serve --port 9090 while running the local server

I guess we can close this? Let me know if anyone has different thoughts

But there is a test for this, isn't it? Maybe rewrite the tests in a way that passes for this case too.

That is simply not possible as we can't test cli port retrying logic without blocking the default port