Skip to content

Commit b0e1589

Browse files
committed
Add scheduled stress test workflow
Signed-off-by: Casper Beyer <casper@synadia.com>
1 parent 00b53dd commit b0e1589

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

.github/workflows/stress.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: stress
2+
on:
3+
schedule:
4+
- cron: "0 0 * * *"
5+
workflow_dispatch:
6+
inputs:
7+
repeat_count:
8+
description: "Number of times to repeat each test"
9+
required: false
10+
default: "100"
11+
parallel_workers:
12+
description: "Number of parallel workers (-n auto or specific number)"
13+
required: false
14+
default: "auto"
15+
16+
jobs:
17+
stress-test:
18+
name: ${{ matrix.project }} stress test (python-${{ matrix.python-version }}, nats-server-${{ matrix.nats-server-version }}, ${{ matrix.os }})
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
python-version: ["3.11", "3.12", "3.13"]
24+
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
25+
nats-server-version: ["latest"]
26+
project: ["nats-core", "nats-server"]
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v5
30+
31+
- name: Set up Go
32+
uses: actions/setup-go@v6
33+
with:
34+
go-version: "stable"
35+
36+
- name: Install NATS Server
37+
run: |
38+
go install github.com/nats-io/nats-server/v2@${{ matrix.nats-server-version }}
39+
shell: bash
40+
41+
- name: Set up Python ${{ matrix.python-version }}
42+
uses: actions/setup-python@v6
43+
with:
44+
python-version: ${{ matrix.python-version }}
45+
46+
- name: Install uv
47+
uses: astral-sh/setup-uv@v6
48+
49+
- name: Install dependencies
50+
run: uv sync --dev
51+
working-directory: ${{ matrix.project }}
52+
53+
- name: Run stress tests for ${{ matrix.project }}
54+
run: uv run pytest -v -n ${{ github.event.inputs.parallel_workers || 'auto' }} --count=${{ github.event.inputs.repeat_count || '100' }}
55+
working-directory: ${{ matrix.project }}
56+
57+
- name: Upload failure artifacts
58+
if: failure()
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: stress-test-failures-${{ matrix.os }}-py${{ matrix.python-version }}
62+
path: ${{ matrix.project }}/.pytest_cache/
63+
retention-days: 7

nats-core/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dev = [
4343
"pytest-asyncio>=0.21.0",
4444
"pytest-cov>=7.0.0",
4545
"pytest-xdist>=3.0.0",
46+
"pytest-repeat>=0.9.0",
4647
"pytest-benchmark>=5.2.1",
4748
]
4849

nats-server/pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ Source = "https://github.com/nats-io/nats.py"
3333
[tool.setuptools.packages.find]
3434
where = ["src"]
3535

36+
[dependency-groups]
37+
dev = [
38+
"pytest>=7.0.0",
39+
"pytest-asyncio>=0.21.0",
40+
"pytest-cov>=7.0.0",
41+
"pytest-xdist>=3.0.0",
42+
"pytest-repeat>=0.9.0",
43+
"pytest-benchmark>=5.2.1",
44+
]
45+
3646
[tool.pytest.ini_options]
3747
asyncio_default_fixture_loop_scope = "function"
3848
asyncio_mode = "auto"

nats-server/tests/test_server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from urllib.parse import urlparse
1111

1212
import pytest
13+
1314
from nats.server import Server, ServerCluster, ServerError, run, run_cluster
1415

1516

@@ -73,6 +74,7 @@ async def fetch_server_info(server: Server) -> ServerInfo:
7374
return info
7475

7576

77+
@pytest.mark.repeat(1)
7678
async def test_run_with_default_port():
7779
"""Test the run function with the default port (4222)."""
7880
# Start with default port (no port specified)
@@ -174,6 +176,7 @@ async def test_run_with_jetstream(jetstream, tmp_path):
174176
await server.shutdown()
175177

176178

179+
@pytest.mark.repeat(1)
177180
async def test_run_with_port_from_config():
178181
"""Test the run function with port specified in config file."""
179182
# Start server with config file that sets port to 4567

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dev = [
44
"pytest-asyncio>=0.21.0",
55
"pytest-cov>=7.0.0",
66
"pytest-xdist>=3.0.0",
7+
"pytest-repeat>=0.9.0",
78
"ty>=0.0.0a6",
89
"ruff>=0.1.0",
910
"codespell>=2.2.0",

uv.lock

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)