Skip to content

Commit 42e3518

Browse files
authored
[IntegrationTest] Use 127.0.0.1 as target address and a random port (#756)
* Use `127.0.0.1` as target address and a random port * Fix spellcheck-docs
1 parent ac1dee9 commit 42e3518

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

docs/spelling_wordlist.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ scm
55
Threadless
66
threadless
77
youtube
8+
socio
9+
sexualized
10+
https
11+
www
12+
html
13+
faq

tests/integration/test_integration.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55

66
import pytest
77

8+
from proxy.common.utils import get_available_port
89
from proxy.common._compat import IS_WINDOWS # noqa: WPS436
910

1011

12+
PROXY_PY_PORT = get_available_port()
13+
14+
1115
# FIXME: Ignore is necessary for as long as pytest hasn't figured out
1216
# FIXME: typing for their fixtures.
1317
# Refs:
@@ -22,6 +26,7 @@ def _proxy_py_instance() -> Generator[None, None, None]:
2226
proxy_cmd = (
2327
'proxy',
2428
'--hostname', '127.0.0.1',
29+
'--port', str(PROXY_PY_PORT),
2530
'--enable-web-server',
2631
)
2732
proxy_proc = Popen(proxy_cmd)
@@ -49,4 +54,4 @@ def test_curl() -> None:
4954
this_test_module = Path(__file__)
5055
shell_script_test = this_test_module.with_suffix('.sh')
5156

52-
check_output(str(shell_script_test))
57+
check_output([str(shell_script_test), str(PROXY_PY_PORT)])

tests/integration/test_integration.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@
99
# to clean up any background process including
1010
# proxy.py
1111

12+
PROXY_PY_PORT=$1
13+
if [[ -z "$PROXY_PY_PORT" ]]; then
14+
echo "PROXY_PY_PORT required as argument."
15+
exit 1
16+
fi
17+
1218
# Wait for server to come up
19+
WAIT_FOR_PROXY="lsof -i TCP:$PROXY_PY_PORT | wc -l | tr -d ' '"
1320
while true; do
14-
if [[ $(lsof -i TCP:8899 | wc -l | tr -d ' ') == 0 ]]; then
21+
if [[ $WAIT_FOR_PORT == 0 ]]; then
1522
echo "Waiting for proxy..."
1623
sleep 1
1724
else
@@ -24,8 +31,8 @@ while true; do
2431
curl -v \
2532
--max-time 1 \
2633
--connect-timeout 1 \
27-
-x localhost:8899 \
28-
http://localhost:8899/ 2>/dev/null
34+
-x 127.0.0.1:$PROXY_PY_PORT \
35+
http://127.0.0.1:$PROXY_PY_PORT/ 2>/dev/null
2936
if [[ $? == 0 ]]; then
3037
break
3138
fi
@@ -41,24 +48,24 @@ done
4148
# detect if we have internet access. If we do,
4249
# then use httpbin.org for integration testing.
4350
curl -v \
44-
-x localhost:8899 \
51+
-x 127.0.0.1:$PROXY_PY_PORT \
4552
http://httpbin.org/get
4653
if [[ $? != 0 ]]; then
4754
echo "http request failed"
4855
exit 1
4956
fi
5057

5158
curl -v \
52-
-x localhost:8899 \
59+
-x 127.0.0.1:$PROXY_PY_PORT \
5360
https://httpbin.org/get
5461
if [[ $? != 0 ]]; then
5562
echo "https request failed"
5663
exit 1
5764
fi
5865

5966
curl -v \
60-
-x localhost:8899 \
61-
http://localhost:8899/
67+
-x 127.0.0.1:$PROXY_PY_PORT \
68+
http://127.0.0.1:$PROXY_PY_PORT/
6269
if [[ $? != 0 ]]; then
6370
echo "http request to built in webserver failed"
6471
exit 1

0 commit comments

Comments
 (0)