-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest
More file actions
executable file
·110 lines (93 loc) · 3.24 KB
/
Copy pathtest
File metadata and controls
executable file
·110 lines (93 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
function steady_is_running() {
curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1
}
find_pids_on_port_via_proc() {
# Parse /proc/net/tcp{,6} to find socket inodes listening on the port,
# then scan /proc/*/fd/ to find which pids own those sockets.
local port_hex
port_hex=$(printf '%04X' "$1")
local inodes
inodes=$(awk -v ph="$port_hex" '$2 ~ ":"ph"$" && $4 == "0A" {print $10}' /proc/net/tcp /proc/net/tcp6 2>/dev/null | sort -u)
[ -z "$inodes" ] && return
local pids=""
for inode in $inodes; do
for fd in /proc/[0-9]*/fd/*; do
if [ "$(readlink "$fd" 2>/dev/null)" = "socket:[$inode]" ]; then
local pid="${fd#/proc/}"
pid="${pid%%/fd/*}"
pids="$pids $pid"
break
fi
done
done
echo "$pids" | xargs
}
kill_server_on_port() {
if command -v lsof >/dev/null 2>&1; then
pids=$(lsof -t -i tcp:"$1" || echo "")
elif command -v ss >/dev/null 2>&1; then
pids=$(ss -tlnp "sport = :$1" 2>/dev/null | grep -oP 'pid=\K[0-9]+' || echo "")
elif command -v fuser >/dev/null 2>&1; then
pids=$(fuser "$1/tcp" 2>/dev/null || echo "")
elif [ -d /proc/net ]; then
pids=$(find_pids_on_port_via_proc "$1")
else
echo "Warning: no tool available to find processes on port $1"
return
fi
if [ "$pids" != "" ]; then
kill $pids
echo "Stopped $pids."
fi
}
function is_overriding_api_base_url() {
[ -n "$TEST_API_BASE_URL" ]
}
if ! is_overriding_api_base_url && ! steady_is_running ; then
# When we exit this script, make sure to kill the background mock server process
trap 'kill_server_on_port 4010' EXIT
# Start the dev server
./scripts/mock --daemon
fi
if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
elif ! steady_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Steady server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the steady command:"
echo
echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}"
echo
exit 1
else
echo -e "${GREEN}✔ Mock steady server is running with your OpenAPI spec${NC}"
echo
fi
export DEFER_PYDANTIC_BUILD=false
# Note that we need to specify the patch version here so that uv
# won't use unstable (alpha, beta, rc) releases for the tests
PY_VERSION_MIN=">=3.9.0"
PY_VERSION_MAX=">=3.14.0"
function run_tests() {
uv run --isolated --all-extras pytest "$@"
}
# If UV_PYTHON is already set in the environment, just run the command once
if [[ -n "$UV_PYTHON" ]]; then
run_tests "$@"
else
# If UV_PYTHON is not set, run the command for min and max versions
echo "==> Running tests for Python $PY_VERSION_MIN"
UV_PYTHON="$PY_VERSION_MIN" run_tests "$@"
echo "==> Running tests for Python $PY_VERSION_MAX"
UV_PYTHON="$PY_VERSION_MAX" run_tests "$@"
fi