Skip to content

Commit

Permalink
tests: cache http responses
Browse files Browse the repository at this point in the history
  • Loading branch information
lilydjwg committed Feb 10, 2025
1 parent fa9ca38 commit 9771d13
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
31 changes: 23 additions & 8 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
# - "3.8"
# - "3.9"
# - "3.10"
# - "3.11"
# - "3.12"
- "3.13"
# pypy fails in some cases but we don't care much about that
# with github actions we can't mark some jobs to not affect the overall
# conclusion so we have to omit "allow-failure" tests.
# See https://github.com/actions/toolkit/issues/399
# - pypy-3.7
deps:
- tornado pycurl
# - tornado pycurl
# timer runs when loop is closed, see https://github.com/lilydjwg/nvchecker/actions/runs/11650699759/job/32439742210
# - aiohttp
- tornado
# - tornado
- httpx[http2]>=0.14.0
exclude: []
steps:
Expand Down Expand Up @@ -60,5 +60,20 @@ jobs:
env:
KEY: ${{ secrets.KEY }}
run: if [[ -n $KEY ]]; then openssl enc -d -aes-256-ctr -pbkdf2 -k $KEY -in keyfile.toml.enc -out keyfile.toml; fi

- name: Setup mitmproxy cache
uses: actions/cache@v4
env:
cache-name: cache-mitm
with:
path: ~/.mitmproxy
key: ${{ env.cache-name }}
restore-keys: |
${{ env.cache-name }}
- name: Install mitmproxy
run: |
sudo apt update
sudo apt install -y mitmproxy bubblewrap
- name: Run pytest
run: if [[ -f keyfile.toml ]]; then KEYFILE=keyfile.toml pytest; else pytest; fi
run: scripts/run_cached_tests
21 changes: 21 additions & 0 deletions scripts/run_cached_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -e

if [[ -f ~/.mitmproxy/nvdump ]]; then
mitmdump -S ~/.mitmproxy/nvdump -p 7890 --server-replay-reuse --server-replay-extra=forward -w newdump &
else
mitmdump -s ~/.mitmproxy/nvdump -p 7890 &
fi

mitm_pid=$!

if [[ -f keyfile.toml ]]; then
export KEYFILE=keyfile.toml
fi

http_proxy=http://localhost:7890 https_proxy=http://localhost:7890 FAKEROOTDONTTRYCHOWN=1 bwrap --dev-bind / / --bind ~/.mitmproxy/mitmproxy-ca-cert.pem /etc/ssl/cert.pem pytest

kill -INT $mitm_pid

if [[ -s newdump ]]; then
cat newdump >> ~/.mitmproxy/nvdump
fi

0 comments on commit 9771d13

Please sign in to comment.