Skip to content

Commit

Permalink
[IntegrationTest] Use 127.0.0.1 as target address and a random port (
Browse files Browse the repository at this point in the history
…#756)

* Use `127.0.0.1` as target address and a random port

* Fix spellcheck-docs
  • Loading branch information
abhinavsingh authored Nov 19, 2021
1 parent ac1dee9 commit 42e3518
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
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
sexualized
https
www
html
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()


# 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

0 comments on commit 42e3518

Please sign in to comment.