-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Testing: use a better way to get a port to the test app #753
Conversation
Still not very robust. Why not ephemeral ports given by |
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? |
Can you elaborate? How are ephemeral ports error pone? |
This is not true. We use portfinder and it'll give an available port. It starts with 8000. |
That's a good idea. I'll update. |
@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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rauchg done.
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. |
But the randomness of the port has no impact in the outcome, correct? Specially considering that ephemeral ports (via |
If the randomness has no impact on the outcome, why do you use it? Why make this PR in that case? |
Because let's say you have something running on port 8000, the tests would have failed for the wrong reason |
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 😄 |
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. |
I think here we started to randomize the base port. But now we are doing something else. |
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. |
@sedubois we always run test in parallel and Jest know how to report them well.
Let's ignore this case for now. Let's do things one by one. This is a good improvement compared with the current setup as we longer using |
👍 |
@sedubois sure but we also run tests upon |
Thanks for your input @sedubois, always much appreciated |
…port-randomization # Conflicts: # package.json # yarn.lock
Merge master into test-get-port-randomization
There was a problem hiding this 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?
I think this is good to merge. |
Awesome ❤️ |
@@ -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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Use http module's
server.listen()
to bind to a random available port.