Skip to content

[IntegrationTest] Use 127.0.0.1 as target address and a random port #756

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

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ scm
Threadless
threadless
youtube
socio
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add these to the document and not globally?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Totally, I added these because CI was failing and making me nervous, haha. Let me address them properly as a follow up PR. I have a few bits more related to doc. Will pull in as part of that.

sexualized
https
www
html
Copy link
Contributor

Choose a reason for hiding this comment

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

This will probably be unnecessary if you fix the document to have an explicit link by wrapping that link with angled brackets.

faq
7 changes: 6 additions & 1 deletion tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

import pytest

from proxy.common.utils import get_available_port
from proxy.common._compat import IS_WINDOWS # noqa: WPS436


PROXY_PY_PORT = get_available_port()
Copy link
Contributor

Choose a reason for hiding this comment

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

It's best to use an ephemeral port. Otherwise, it's still possible to hit race conditions.

Copy link
Owner Author

@abhinavsingh abhinavsingh Nov 19, 2021

Choose a reason for hiding this comment

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

Yep I would have, but situation here is a little different. Proxy is not in running in embedded mode but started using command line. So we must then either parse port from logs or let proxy write the port somewhere or use pid file to infer the port :). I went for the easy solution for now.



# FIXME: Ignore is necessary for as long as pytest hasn't figured out
# FIXME: typing for their fixtures.
# Refs:
Expand All @@ -22,6 +26,7 @@ def _proxy_py_instance() -> Generator[None, None, None]:
proxy_cmd = (
'proxy',
'--hostname', '127.0.0.1',
'--port', str(PROXY_PY_PORT),
'--enable-web-server',
)
proxy_proc = Popen(proxy_cmd)
Expand Down Expand Up @@ -49,4 +54,4 @@ def test_curl() -> None:
this_test_module = Path(__file__)
shell_script_test = this_test_module.with_suffix('.sh')

check_output(str(shell_script_test))
check_output([str(shell_script_test), str(PROXY_PY_PORT)])
21 changes: 14 additions & 7 deletions tests/integration/test_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
# to clean up any background process including
# proxy.py

PROXY_PY_PORT=$1
if [[ -z "$PROXY_PY_PORT" ]]; then
echo "PROXY_PY_PORT required as argument."
exit 1
fi

# Wait for server to come up
WAIT_FOR_PROXY="lsof -i TCP:$PROXY_PY_PORT | wc -l | tr -d ' '"
while true; do
if [[ $(lsof -i TCP:8899 | wc -l | tr -d ' ') == 0 ]]; then
if [[ $WAIT_FOR_PORT == 0 ]]; then
echo "Waiting for proxy..."
sleep 1
else
Expand All @@ -24,8 +31,8 @@ while true; do
curl -v \
--max-time 1 \
--connect-timeout 1 \
-x localhost:8899 \
http://localhost:8899/ 2>/dev/null
-x 127.0.0.1:$PROXY_PY_PORT \
http://127.0.0.1:$PROXY_PY_PORT/ 2>/dev/null
if [[ $? == 0 ]]; then
break
fi
Expand All @@ -41,24 +48,24 @@ done
# detect if we have internet access. If we do,
# then use httpbin.org for integration testing.
curl -v \
-x localhost:8899 \
-x 127.0.0.1:$PROXY_PY_PORT \
http://httpbin.org/get
if [[ $? != 0 ]]; then
echo "http request failed"
exit 1
fi

curl -v \
-x localhost:8899 \
-x 127.0.0.1:$PROXY_PY_PORT \
https://httpbin.org/get
if [[ $? != 0 ]]; then
echo "https request failed"
exit 1
fi

curl -v \
-x localhost:8899 \
http://localhost:8899/
-x 127.0.0.1:$PROXY_PY_PORT \
http://127.0.0.1:$PROXY_PY_PORT/
if [[ $? != 0 ]]; then
echo "http request to built in webserver failed"
exit 1
Expand Down