| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -ex -o pipefail |
| 4 |
|
| 5 |
# disable warnings about pyright being out of date |
| 6 |
# used in test_exports and in check.sh |
| 7 |
export PYRIGHT_PYTHON_IGNORE_WARNINGS=1 |
| 8 |
|
| 9 |
# Log some general info about the environment |
| 10 |
echo "::group::Environment" |
| 11 |
uname -a |
| 12 |
env | sort |
| 13 |
echo "::endgroup::" |
| 14 |
|
| 15 |
# Curl's built-in retry system is not very robust; it gives up on lots of |
| 16 |
# network errors that we want to retry on. Wget might work better, but it's |
| 17 |
# not installed on azure pipelines's windows boxes. So... let's try some good |
| 18 |
# old-fashioned brute force. (This is also a convenient place to put options |
| 19 |
# we always want, like -f to tell curl to give an error if the server sends an |
| 20 |
# error response, and -L to follow redirects.) |
| 21 |
function curl-harder() { |
| 22 |
for BACKOFF in 0 1 2 4 8 15 15 15 15; do |
| 23 |
sleep $BACKOFF |
| 24 |
if curl -fL --connect-timeout 5 "$@"; then |
| 25 |
return 0 |
| 26 |
fi |
| 27 |
done |
| 28 |
return 1 |
| 29 |
} |
| 30 |
|
| 31 |
################################################################ |
| 32 |
# We have a Python environment! |
| 33 |
################################################################ |
| 34 |
|
| 35 |
echo "::group::Versions" |
| 36 |
python -c "import sys, struct, ssl; print('python:', sys.version); print('version_info:', sys.version_info); print('bits:', struct.calcsize('P') * 8); print('openssl:', ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO)" |
| 37 |
echo "::endgroup::" |
| 38 |
|
| 39 |
echo "::group::Install dependencies" |
| 40 |
python -m pip install -U pip uv -c test-requirements.txt |
| 41 |
python -m pip --version |
| 42 |
python -m uv --version |
| 43 |
|
| 44 |
python -m uv pip install build |
| 45 |
|
| 46 |
python -m build |
| 47 |
wheel_package=$(ls dist/*.whl) |
| 48 |
python -m uv pip install "trio @ $wheel_package" -c test-requirements.txt |
| 49 |
|
| 50 |
# Actual tests |
| 51 |
# expands to 0 != 1 if NO_TEST_REQUIREMENTS is not set, if set the `-0` has no effect |
| 52 |
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 |
| 53 |
if [ "${NO_TEST_REQUIREMENTS-0}" == 1 ]; then |
| 54 |
python -m uv pip install pytest coverage -c test-requirements.txt |
| 55 |
flags="--skip-optional-imports" |
| 56 |
else |
| 57 |
python -m uv pip install -r test-requirements.txt --no-deps |
| 58 |
flags="" |
| 59 |
fi |
| 60 |
|
| 61 |
# If we're testing with a LSP installed, then it might break network |
| 62 |
# stuff, so wait until after we've finished setting everything else |
| 63 |
# up. |
| 64 |
if [ "$LSP" != "" ]; then |
| 65 |
echo "Installing LSP from ${LSP}" |
| 66 |
# We use --insecure because one of the LSP's has been observed to give |
| 67 |
# cert verification errors: |
| 68 |
# |
| 69 |
# https://github.com/python-trio/trio/issues/1478 |
| 70 |
# |
| 71 |
# *Normally*, you should never ever use --insecure, especially when |
| 72 |
# fetching an executable! But *in this case*, we're intentionally |
| 73 |
# installing some untrustworthy quasi-malware onto into a sandboxed |
| 74 |
# machine for testing. So MITM attacks are really the least of our |
| 75 |
# worries. |
| 76 |
if [ "$LSP_EXTRACT_FILE" != "" ]; then |
| 77 |
# We host the Astrill VPN installer ourselves, and encrypt it |
| 78 |
# so as to decrease the chances of becoming an inadvertent |
| 79 |
# public redistributor. |
| 80 |
curl-harder -o lsp-installer.zip "$LSP" |
| 81 |
unzip -P "not very secret trio ci key" lsp-installer.zip "$LSP_EXTRACT_FILE" |
| 82 |
mv "$LSP_EXTRACT_FILE" lsp-installer.exe |
| 83 |
else |
| 84 |
curl-harder --insecure -o lsp-installer.exe "$LSP" |
| 85 |
fi |
| 86 |
# This is only needed for the Astrill LSP, but there's no harm in |
| 87 |
# doing it all the time. The cert was manually extracted by installing |
| 88 |
# the package in a VM, clicking "Always trust from this publisher" |
| 89 |
# when installing, and then running 'certmgr.msc' and exporting the |
| 90 |
# certificate. See: |
| 91 |
# http://www.migee.com/2010/09/24/solution-for-unattendedsilent-installs-and-would-you-like-to-install-this-device-software/ |
| 92 |
certutil -addstore "TrustedPublisher" src/trio/_tests/astrill-codesigning-cert.cer |
| 93 |
# Double-slashes are how you tell windows-bash that you want a single |
| 94 |
# slash, and don't treat this as a unix-style filename that needs to |
| 95 |
# be replaced by a windows-style filename. |
| 96 |
# http://www.mingw.org/wiki/Posix_path_conversion |
| 97 |
./lsp-installer.exe //silent //norestart |
| 98 |
echo "Waiting for LSP to appear in Winsock catalog" |
| 99 |
while ! netsh winsock show catalog | grep "Layered Chain Entry"; do |
| 100 |
sleep 1 |
| 101 |
done |
| 102 |
netsh winsock show catalog |
| 103 |
fi |
| 104 |
echo "::endgroup::" |
| 105 |
|
| 106 |
echo "::group::Setup for tests" |
| 107 |
|
| 108 |
# We run the tests from inside an empty directory, to make sure Python |
| 109 |
# doesn't pick up any .py files from our working dir. Might have already |
| 110 |
# been created by a previous run. |
| 111 |
mkdir empty || true |
| 112 |
cd empty |
| 113 |
|
| 114 |
INSTALLDIR=$(python -c "import os, trio; print(os.path.dirname(trio.__file__))") |
| 115 |
cp ../pyproject.toml "$INSTALLDIR" # TODO: remove this |
| 116 |
|
| 117 |
# get mypy tests a nice cache |
| 118 |
MYPYPATH=".." mypy --config-file= --cache-dir=./.mypy_cache -c "import trio" >/dev/null 2>/dev/null || true |
| 119 |
|
| 120 |
# support subprocess spawning with coverage.py |
| 121 |
echo "import coverage; coverage.process_startup()" | tee -a "$INSTALLDIR/../sitecustomize.py" |
| 122 |
|
| 123 |
perl -i -pe 's/-p trio\._tests\.pytest_plugin//' "$INSTALLDIR/pyproject.toml" |
| 124 |
|
| 125 |
echo "::endgroup::" |
| 126 |
echo "::group:: Run Tests" |
| 127 |
if PYTHONPATH=../tests COVERAGE_PROCESS_START=$(pwd)/../pyproject.toml \ |
| 128 |
coverage run --rcfile=../pyproject.toml -m \ |
| 129 |
pytest -ra --junitxml=../test-results.xml \ |
| 130 |
-p _trio_check_attrs_aliases --verbose --durations=10 \ |
| 131 |
-p trio._tests.pytest_plugin --run-slow $flags "${INSTALLDIR}"; then |
| 132 |
PASSED=true |
| 133 |
else |
| 134 |
PASSED=false |
| 135 |
fi |
| 136 |
echo "::endgroup::" |
| 137 |
echo "::group::Coverage" |
| 138 |
|
| 139 |
coverage combine --rcfile ../pyproject.toml |
| 140 |
cd .. # coverage needs to be in the folder containing src/trio |
| 141 |
cp empty/.coverage . |
| 142 |
coverage report -m --rcfile ./pyproject.toml |
| 143 |
coverage xml --rcfile ./pyproject.toml |
| 144 |
|
| 145 |
# Remove the LSP again; again we want to do this ASAP to avoid |
| 146 |
# accidentally breaking other stuff. |
| 147 |
if [ "$LSP" != "" ]; then |
| 148 |
netsh winsock reset |
| 149 |
fi |
| 150 |
|
| 151 |
echo "::endgroup::" |
| 152 |
$PASSED |