-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webdriver tests.
- Loading branch information
Showing
15 changed files
with
871 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[run] | ||
branch = True | ||
source = | ||
. | ||
omit = | ||
.tox/* | ||
/usr/* | ||
*/tmp* | ||
setup.py | ||
# Don't complain if non-runnable code isn't run | ||
*/__main__.py | ||
yelp_styleguide/templates/*.py | ||
# Coverage is incorrectly reported for distutils/__init__.py only when in venv, causing < 100% | ||
*/distutils/__init__.py | ||
|
||
[report] | ||
exclude_lines = | ||
# Have to re-enable the standard pragma | ||
\#\s*pragma: no cover | ||
|
||
# Don't complain if tests don't hit defensive assertion code: | ||
^\s*raise AssertionError\b | ||
^\s*raise NotImplementedError\b | ||
^\s*return NotImplemented\b | ||
^\s*raise$ | ||
|
||
# Don't complain if non-runnable code isn't run: | ||
^if __name__ == ['"]__main__['"]:$ | ||
[html] | ||
directory = coverage-html | ||
# vim:ft=dosini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.cache | ||
._* | ||
*.egg | ||
*.eggs | ||
*.egg-info | ||
*.iml | ||
*.py[co] | ||
.*.sw[a-z] | ||
.coverage | ||
.idea | ||
.project | ||
.pydevproject | ||
.tox | ||
.venv.touch | ||
/venv* | ||
coverage-html | ||
dist |
25 changes: 25 additions & 0 deletions
25
tests/third-party/ephemeral-port-reserve/.pre-commit-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.4.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: debug-statements | ||
- id: name-tests-test | ||
- id: check-added-large-files | ||
- repo: https://github.com/pre-commit/mirrors-autopep8 | ||
rev: v1.4.4 | ||
hooks: | ||
- id: autopep8 | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 3.7.9 | ||
hooks: | ||
- id: flake8 | ||
- repo: https://github.com/asottile/reorder_python_imports | ||
rev: v1.8.0 | ||
hooks: | ||
- id: reorder-python-imports | ||
args: [ | ||
'--add-import', 'from __future__ import absolute_import', | ||
'--add-import', 'from __future__ import unicode_literals', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: python | ||
matrix: | ||
include: | ||
- env: TOXENV=py27 | ||
python: 2.7 | ||
- env: TOXENV=py35 | ||
python: 3.5 | ||
- env: TOXENV=py36 | ||
python: 3.6 | ||
- env: TOXENV=pypy | ||
python: pypy | ||
install: pip install coveralls tox | ||
script: tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Yelp | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# `ephemeral-port-reserve` | ||
Sometimes you need a networked program to bind to a port that can't be hard-coded. | ||
Generally this is when you want to run several of them in parallel; if they all | ||
bind to port 8080, only one of them can succeed. | ||
|
||
The usual solution is the "port 0 trick". If you bind to port 0, your kernel will | ||
find some arbitrary high-numbered port that's unused and bind to that. Afterward | ||
you can query the actual port that was bound to if you need to use the port number | ||
elsewhere. However, there are cases where the port 0 trick won't work. For example, | ||
mysqld takes port 0 to mean "the port configured in my.cnf". Docker can bind your | ||
containers to port 0, but uses its own implementation to find a free port which | ||
races and fails in the face of parallelism. | ||
|
||
`ephemeral-port-reserve` provides an implementation of the port 0 trick which | ||
is reliable and race-free. You can use it like so: | ||
|
||
```!bash | ||
PORT="$(ephemeral-port-reserve)" | ||
docker run -p 127.0.0.1:$PORT:5000 registry:2 | ||
``` | ||
|
||
|
||
`ephemeral-port-reserve` is a utility to bind to an ephemeral port, force it into | ||
the `TIME_WAIT` state, and unbind it. | ||
|
||
This means that further ephemeral port alloctions won't pick this "reserved" port, | ||
but subprocesses can still bind to it explicitly, given that they use `SO_REUSEADDR`. | ||
By default on linux you have a grace period of 60 seconds to reuse this port. | ||
To check your own particular value: | ||
|
||
```!bash | ||
$ cat /proc/sys/net/ipv4/tcp_fin_timeout | ||
60 | ||
``` | ||
|
||
**NOTE:** By default, the port returned is *specifically* for `localhost`, aka `127.0.0.1`. | ||
If you bind instead to `0.0.0.0`, you may encounter a port conflict. If you need to | ||
bind to a non-localhost IP, you can pass it as the first argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Name: Ephemeral Port Reserve | ||
URL: https://github.com/Yelp/ephemeral-port-reserve | ||
Copy: https://github.com/toitware/ephemeral-port-reserve | ||
Revision: 6cf5addc2f1d5c0a25be4ba4af62104da1d8fc51 | ||
Date: 2024-08-22 | ||
License: MIT | ||
|
||
Description: | ||
A utility to bind to an ephemeral port, force it into the TIME_WAIT state, and unbind it. | ||
|
||
This means that further ephemeral port alloctions won't pick this "reserved" port, but | ||
subprocesses can still bind to it explicitly, given that they use SO_REUSEADDR. By | ||
default on linux you have a grace period of 60 seconds to reuse this port. | ||
|
||
Changes: | ||
No changes except to remove unnecessary files. |
61 changes: 61 additions & 0 deletions
61
tests/third-party/ephemeral-port-reserve/ephemeral_port_reserve.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import contextlib | ||
import errno | ||
from socket import error as SocketError | ||
from socket import SO_REUSEADDR | ||
from socket import socket | ||
from socket import SOL_SOCKET | ||
|
||
LOCALHOST = '127.0.0.1' | ||
|
||
|
||
def reserve(ip=LOCALHOST, port=0): | ||
"""Bind to an ephemeral port, force it into the TIME_WAIT state, and unbind it. | ||
This means that further ephemeral port alloctions won't pick this "reserved" port, | ||
but subprocesses can still bind to it explicitly, given that they use SO_REUSEADDR. | ||
By default on linux you have a grace period of 60 seconds to reuse this port. | ||
To check your own particular value: | ||
$ cat /proc/sys/net/ipv4/tcp_fin_timeout | ||
60 | ||
By default, the port will be reserved for localhost (aka 127.0.0.1). | ||
To reserve a port for a different ip, provide the ip as the first argument. | ||
Note that IP 0.0.0.0 is interpreted as localhost. | ||
""" | ||
port = int(port) | ||
with contextlib.closing(socket()) as s: | ||
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) | ||
try: | ||
s.bind((ip, port)) | ||
except SocketError as e: | ||
# socket.error: EADDRINUSE Address already in use | ||
if e.errno == errno.EADDRINUSE and port != 0: | ||
s.bind((ip, 0)) | ||
else: | ||
raise | ||
|
||
# the connect below deadlocks on kernel >= 4.4.0 unless this arg is greater than zero | ||
s.listen(1) | ||
|
||
sockname = s.getsockname() | ||
|
||
# these three are necessary just to get the port into a TIME_WAIT state | ||
with contextlib.closing(socket()) as s2: | ||
s2.connect(sockname) | ||
sock, _ = s.accept() | ||
with contextlib.closing(sock): | ||
return sockname[1] | ||
|
||
|
||
def main(): # pragma: no cover | ||
from sys import argv | ||
port = reserve(*argv[1:]) | ||
print(port) | ||
|
||
|
||
if __name__ == '__main__': | ||
exit(main()) |
Oops, something went wrong.