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

Testing: use a better way to get a port to the test app #753

Merged
merged 7 commits into from
Feb 9, 2017

Conversation

arunoda
Copy link
Contributor

@arunoda arunoda commented Jan 12, 2017

Use http module's server.listen() to bind to a random available port.

@rauchg
Copy link
Member

rauchg commented Jan 12, 2017

Still not very robust. Why not ephemeral ports given by listen() ?

@sedubois
Copy link
Contributor

Random behavior in tests is nice but can also lead to randomly failing tests sometimes hard to track down (saw that in my previous company). How about testing several startups using a predefined list of ports?

@rauchg
Copy link
Member

rauchg commented Jan 12, 2017

Can you elaborate? How are ephemeral ports error pone?

@arunoda
Copy link
Contributor Author

arunoda commented Jan 13, 2017

Random behavior in tests is nice but can also lead to randomly failing tests sometimes hard to track down

This is not true. We use portfinder and it'll give an available port. It starts with 8000.
Here we've randomized that.

@arunoda
Copy link
Contributor Author

arunoda commented Jan 13, 2017

Still not very robust. Why not ephemeral ports given by listen() ?

That's a good idea. I'll update.

@arunoda
Copy link
Contributor Author

arunoda commented Jan 13, 2017

@rauchg updated as you suggested.

yarn.lock Outdated
dependencies:
nodegit-promise "~4.0.0"
object-assign "^4.0.1"

prr@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/prr/-/prr-0.0.0.tgz#1a84b85908325501411853d0081ee3fa86e2926a"
Copy link
Member

Choose a reason for hiding this comment

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

when you remove a project, you need to re-instantiate the lock. we should be seeing red here, for portmapper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep yep. Need to do it. I use both npm and yarn at the same time. That's a bad habit.

Will update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rauchg done.

@sedubois
Copy link
Contributor

Can you elaborate?

I was just speaking in a general context. A test which is based on random behavior isn't repeatable. It might start to fail sometimes but not every time, might be quite unsettling. A test (explicitly or not) has 3 parts: the "given", the "when" and the "then". It would be quite helpful to know the "given" just by reading the source code.

@rauchg
Copy link
Member

rauchg commented Jan 13, 2017

But the randomness of the port has no impact in the outcome, correct? Specially considering that ephemeral ports (via listen()) always give us a free port.

@sedubois
Copy link
Contributor

If the randomness has no impact on the outcome, why do you use it? Why make this PR in that case?

@rauchg
Copy link
Member

rauchg commented Jan 13, 2017

Because let's say you have something running on port 8000, the tests would have failed for the wrong reason

@sedubois
Copy link
Contributor

sedubois commented Jan 13, 2017

I just hadn't understood why that port would be randomly unavailable in the first place. Normally the point of a test env is to offer a reproducible context.

Anyways can just discard my comments, it's just that the subject of randomness triggered some sensitive memories from a past life at F-Secure 😄

@sedubois
Copy link
Contributor

sedubois commented Jan 13, 2017

I hope the port isn't randomly unavailable in the test automation env? So it's on some developers' laptops that the issue arises? Then other option than randomness might be to allow the dev to configure the port when running tests (with a sensible default).

@rauchg as you said elsewhere, explicit is better than implicit, when possible.

@arunoda arunoda changed the title Randomize the port returned from test util's findPort(). Testing: use a better way to get a port to the test app Jan 13, 2017
@arunoda
Copy link
Contributor Author

arunoda commented Jan 13, 2017

I think here we started to randomize the base port. But now we are doing something else.
We let node's http module to pick an available port and use for the test app.

@sedubois
Copy link
Contributor

Other issue with random port is that it might hide the fact that another instance of the tests might have been stuck and left running elsewhere on the machine.

@arunoda
Copy link
Contributor Author

arunoda commented Jan 13, 2017

@sedubois we always run test in parallel and Jest know how to report them well.

it might hide the fact that another instance of the tests might have been stuck and left running elsewhere on the machine.

Let's ignore this case for now. Let's do things one by one.
We can create a new issue and continue.

This is a good improvement compared with the current setup as we longer using portfinder.

@sedubois
Copy link
Contributor

👍

@rauchg
Copy link
Member

rauchg commented Jan 13, 2017

I just hadn't understood why that port would be randomly unavailable in the first place. Normally the point of a test env is to offer a reproducible context.

@sedubois sure but we also run tests upon prepush, prepublish, so the tests have to be useful on developer machines

@rauchg
Copy link
Member

rauchg commented Jan 13, 2017

Thanks for your input @sedubois, always much appreciated

@timneutkens
Copy link
Member

@arunoda updated the branch arunoda#1.

Merge master into test-get-port-randomization
Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

Looks good 👍 @arunoda ready for merge?

@arunoda
Copy link
Contributor Author

arunoda commented Feb 9, 2017

I think this is good to merge.

@timneutkens timneutkens merged commit 355c984 into vercel:master Feb 9, 2017
@timneutkens
Copy link
Member

Awesome ❤️

@arunoda arunoda deleted the test-get-port-randomization branch February 9, 2017 13:40
@@ -104,9 +104,6 @@
"jest-cli": "^18.0.0",
"node-fetch": "^1.6.3",
"nyc": "^10.0.0",
"portfinder": "^1.0.10",
"react": "15.4.2",
"react-dom": "15.4.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't remove react and react-dom. Tests fail when you did clean install.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, my fault when resolving merge conflicts.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants