Repository navigation
Expand file tree
/
Copy pathrun_tests_own.sh
More file actions
executable file
·133 lines (98 loc) · 3.28 KB
/
Copy pathrun_tests_own.sh
File metadata and controls
executable file
·133 lines (98 loc) · 3.28 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
set -eux
echo "HOME DIR IS [`realpath ~/`]"
echo "WORK DIR IS [$(pwd)]"
# Filter tests for local execution (without remote/ssh)
if [ -z ${TEST_FILTER+x} ]; then
export TEST_FILTER=""
fi
echo NPROC: $(nproc)
# Check for the presence of pg_config
echo check that pg_config is in PATH
command -v pg_config
# Setting up the Python environment
VENV_PATH="/tmp/testgres_venv"
rm -rf $VENV_PATH
${PYTHON_BINARY} -m venv "${VENV_PATH}"
export VIRTUAL_ENV_DISABLE_PROMPT=1
source "${VENV_PATH}/bin/activate"
pip install --upgrade pip setuptools wheel
pip install -r tests/requirements.txt
# remove existing coverage file
export COVERAGE_FILE=.coverage
rm -f $COVERAGE_FILE
pip install coverage
if [ -n "${TEST_CFG__REMOTE_HOST:-}" ] && [ -n "${TEST_CFG__REMOTE_USERNAME:-}" ]; then
cmd_str="ssh"
if [ -n "${TEST_CFG__REMOTE_PASSWORD:-}" ]; then
cmd_str="sshpass -p \"$TEST_CFG__REMOTE_PASSWORD\" $cmd_str"
fi
[ -n "${TEST_CFG__REMOTE_SSH_KEY:-}" ] && cmd_str="$cmd_str -i \"$TEST_CFG__REMOTE_SSH_KEY\""
[ -n "${TEST_CFG__REMOTE_PORT:-}" ] && cmd_str="$cmd_str -p \"$TEST_CFG__REMOTE_PORT\""
REMOTE_SSH_PREFIX="$cmd_str \"$TEST_CFG__REMOTE_USERNAME@$TEST_CFG__REMOTE_HOST\""
else
REMOTE_SSH_PREFIX=""
fi
exec_command() {
local cmd="$1"
local prefix="$2"
eval "$prefix $cmd"
}
show_fs_state__impl() {
local prefix="$1"
local host_label="$2"
set +x
echo "------------- ${host_label} FS STATE"
set -x
exec_command "df -P" "$prefix"
}
check_leftover_ports__impl() {
local prefix="$1"
local host_label="$2"
local ports_dir="/tmp/testgres/ports"
set +x
echo "------------- Checking ${host_label} ports lock directory"
set -x
# Check command: will print FOUND if the directory exists and is not empty
local check_cmd="if [ -d '${ports_dir}' ] && [ \"\$(ls -A '${ports_dir}' 2>/dev/null)\" ]; then echo 'FOUND'; fi"
# Temporarily disable bash's instant drop (set +e) to safely intercept the result
set +e
local result
result=$(exec_command "$check_cmd" "$prefix")
set -e
set +x
if [ "$result" = "FOUND" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Leftover ports detected in $ports_dir on $host_label machine!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
set -x
# We display a list of frozen ports so that the culprits can be identified
exec_command "ls -la '$ports_dir'" "$prefix"
# We hard-drop the entire control script
# sleep 3600
exit 1
else
echo "Clear. No leftover port locks."
fi
set -x
}
fs_verification__impl() {
show_fs_state__impl "$1" "$2"
check_leftover_ports__impl "$1" "$2"
}
fs_verification() {
fs_verification__impl "" "LOCAL"
if [ -n "$REMOTE_SSH_PREFIX" ]; then
fs_verification__impl "$REMOTE_SSH_PREFIX" "REMOTE"
fi
}
# ---------------------------------------- PATH
fs_verification
# run tests (PATH)
echo "HOME DIR IS [`realpath ~/`]"
echo "WORK DIR IS [$(pwd)]"
time coverage run -a -m pytest -l -vvv -n 4 -k "${TEST_FILTER}"
# ---------------------------------------- finish
fs_verification
# ---------------------------------------- coverage
coverage report