Skip to content

Commit edf482e

Browse files
authored
Merge pull request #2974 from opentensor/feat/roman/Improve-test-infrastructure
Improve test infrastructure
2 parents ea3159f + 3e36ff1 commit edf482e

File tree

3 files changed

+389
-97
lines changed

3 files changed

+389
-97
lines changed

.github/workflows/e2e-subtensor-tests.yaml

Lines changed: 25 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ concurrency:
66

77
on:
88
push:
9-
branches: [master, development, staging]
10-
9+
branches:
10+
- '**'
1111
pull_request:
12-
branches: [master, development, staging]
12+
branches:
13+
- '**'
1314
types: [ opened, synchronize, reopened, ready_for_review ]
1415

15-
schedule:
16-
- cron: '0 9 * * *' # Run every night at 2:00 PST
17-
1816
workflow_dispatch:
1917
inputs:
2018
verbose:
@@ -28,7 +26,7 @@ env:
2826

2927
# job to run tests in parallel
3028
jobs:
31-
29+
# Looking for e2e tests
3230
find-tests:
3331
runs-on: ubuntu-latest
3432
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
@@ -44,20 +42,36 @@ jobs:
4442
test_files=$(find tests/e2e_tests -name "test*.py" | jq -R -s -c 'split("\n") | map(select(. != ""))')
4543
# keep it here for future debug
4644
# test_files=$(find tests/e2e_tests -type f -name "test*.py" | grep -E 'test_(hotkeys|staking)\.py$' | jq -R -s -c 'split("\n") | map(select(. != ""))')
45+
echo "Found test files: $test_files"
4746
echo "test-files=$test_files" >> "$GITHUB_OUTPUT"
4847
shell: bash
4948

49+
# Pull docker image
5050
pull-docker-image:
5151
runs-on: ubuntu-latest
52+
outputs:
53+
image-name: ${{ steps.set-output.outputs.image-name }}
5254
steps:
55+
- name: Set Docker image tag based on branch
56+
id: set-output
57+
run: |
58+
ref="${{ github.ref_name }}"
59+
if [[ "$ref" == "master" ]]; then
60+
image="ghcr.io/opentensor/subtensor-localnet:main"
61+
else
62+
image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
63+
fi
64+
echo "Using image: $image"
65+
echo "image-name=$image" >> "$GITHUB_OUTPUT"
66+
5367
- name: Log in to GitHub Container Registry
5468
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
5569

5670
- name: Pull Docker Image
57-
run: docker pull ghcr.io/opentensor/subtensor-localnet:devnet-ready
71+
run: docker pull ${{ steps.set-output.outputs.image-name }}
5872

5973
- name: Save Docker Image to Cache
60-
run: docker save -o subtensor-localnet.tar ghcr.io/opentensor/subtensor-localnet:devnet-ready
74+
run: docker save -o subtensor-localnet.tar ${{ steps.set-output.outputs.image-name }}
6175

6276
- name: Upload Docker Image as Artifact
6377
uses: actions/upload-artifact@v4
@@ -104,95 +118,9 @@ jobs:
104118
- name: Load Docker Image
105119
run: docker load -i subtensor-localnet.tar
106120

107-
# - name: Run tests
108-
# run: uv run pytest ${{ matrix.test-file }} -s
109-
110121
- name: Run tests with retry
111-
run: |
112-
set +e
113-
for i in 1 2 3; do
114-
echo "🔁 Attempt $i: Running tests"
115-
uv run pytest ${{ matrix.test-file }} -s
116-
status=$?
117-
if [ $status -eq 0 ]; then
118-
echo "✅ Tests passed on attempt $i"
119-
break
120-
else
121-
echo "❌ Tests failed on attempt $i"
122-
if [ $i -eq 3 ]; then
123-
echo "Tests failed after 3 attempts"
124-
exit 1
125-
fi
126-
echo "Retrying..."
127-
sleep 5
128-
fi
129-
done
130-
131-
# run non-fast-blocks only on Saturday and by cron schedule
132-
check-if-saturday:
133-
if: github.event_name == 'schedule'
134-
runs-on: ubuntu-latest
135-
outputs:
136-
is-saturday: ${{ steps.check.outputs.is-saturday }}
137-
steps:
138-
- id: check
139-
run: |
140-
day=$(date -u +%u)
141-
echo "Today is weekday $day"
142-
if [ "$day" -ne 6 ]; then
143-
echo "⏭️ Skipping: not Saturday"
144-
echo "is-saturday=false" >> "$GITHUB_OUTPUT"
145-
exit 0
146-
fi
147-
echo "is-saturday=true"
148-
echo "is-saturday=true" >> "$GITHUB_OUTPUT"
149-
150-
151-
cron-run-non-fast-blocks-e2e-test:
152-
if: github.event_name == 'schedule' && needs.check-if-saturday.outputs.is-saturday == 'true'
153-
name: "NFB: ${{ matrix.test-file }} / Python ${{ matrix.python-version }}"
154-
needs:
155-
- check-if-saturday
156-
- find-tests
157-
- pull-docker-image
158-
runs-on: ubuntu-latest
159-
timeout-minutes: 1440
160-
161-
strategy:
162-
fail-fast: false # Allow other matrix jobs to run even if this job fails
163-
max-parallel: 32 # Set the maximum number of parallel jobs (same as we have cores in ubuntu-latest runner)
164-
matrix:
165-
os:
166-
- ubuntu-latest
167-
test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }}
168-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
169-
170-
steps:
171-
- name: Check-out repository
172-
uses: actions/checkout@v4
173-
174-
- name: Set up Python ${{ matrix.python-version }}
175-
uses: actions/setup-python@v5
176-
with:
177-
python-version: ${{ matrix.python-version }}
178-
179-
- name: Install uv
180-
uses: astral-sh/setup-uv@v4
181-
182-
- name: install dependencies
183-
run: uv sync --extra dev --dev
184-
185-
- name: Download Cached Docker Image
186-
uses: actions/download-artifact@v4
187-
with:
188-
name: subtensor-localnet
189-
190-
- name: Load Docker Image
191-
run: docker load -i subtensor-localnet.tar
192-
193-
- name: Run patched E2E tests
194122
env:
195-
FAST_BLOCKS: "0"
123+
LOCALNET_IMAGE_NAME: ${{ needs.pull-docker-image.outputs.image-name }}
196124
run: |
197125
set +e
198126
for i in 1 2 3; do
@@ -212,3 +140,4 @@ jobs:
212140
sleep 5
213141
fi
214142
done
143+

0 commit comments

Comments
 (0)