Skip to content

Commit 73aa385

Browse files
committed
ci(tracker-core): add mysql compatibility matrix job
1 parent e21e23b commit 73aa385

4 files changed

Lines changed: 61 additions & 35 deletions

File tree

.github/workflows/testing.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,41 @@ jobs:
133133
name: Run Unit Tests
134134
run: cargo test --tests --benches --examples --workspace --all-targets --all-features
135135

136+
database-compatibility:
137+
name: Database Compatibility (${{ matrix.mysql-version }})
138+
runs-on: ubuntu-latest
139+
needs: unit
140+
141+
strategy:
142+
matrix:
143+
mysql-version: ["8.0", "8.4"]
144+
145+
steps:
146+
- id: checkout
147+
name: Checkout Repository
148+
uses: actions/checkout@v6
149+
150+
- id: setup
151+
name: Setup Toolchain
152+
uses: dtolnay/rust-toolchain@stable
153+
with:
154+
toolchain: stable
155+
156+
- id: cache
157+
name: Enable Job Cache
158+
uses: Swatinem/rust-cache@v2
159+
136160
- id: database
137-
name: Run MySQL Database Tests
138-
run: TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=true cargo test --package bittorrent-tracker-core
161+
name: Run Database Compatibility Test
162+
env:
163+
TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST: "true"
164+
TORRUST_TRACKER_CORE_MYSQL_DRIVER_IMAGE_TAG: ${{ matrix.mysql-version }}
165+
run: cargo test -p bittorrent-tracker-core --features db-compatibility-tests run_mysql_driver_tests -- --nocapture
139166

140167
e2e:
141168
name: E2E
142169
runs-on: ubuntu-latest
143-
needs: unit
170+
needs: database-compatibility
144171

145172
strategy:
146173
matrix:

docs/issues/1703-1525-01-persistence-test-coverage.md

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The implementation must follow these quality rules for all new and modified test
4444

4545
The PR #1695 review branch includes a QA script that defines the expected behavior:
4646

47-
- `run-db-compatibility-matrix.sh`:
47+
- `database-compatibility` job in `.github/workflows/testing.yaml`:
4848
executes a compatibility matrix across SQLite, multiple MySQL versions, and multiple PostgreSQL
4949
versions.
5050

@@ -88,51 +88,44 @@ Steps:
8888
- PostgreSQL (reserved for subissue #1525-08): `TORRUST_TRACKER_CORE_POSTGRES_DRIVER_IMAGE_TAG`
8989

9090
When `TORRUST_TRACKER_CORE_MYSQL_DRIVER_IMAGE_TAG` is not set, the test falls back to the
91-
current hardcoded default (e.g. `8.0`), preserving existing behavior. The matrix script sets
91+
current hardcoded default (e.g. `8.0`), preserving existing behavior. The CI matrix job sets
9292
this variable explicitly for each version in the loop, so unset means "run as today" and the
9393
matrix just expands that into multiple combinations.
9494

95-
- Add `contrib/dev-tools/qa/run-db-compatibility-matrix.sh` modeled after the PR prototype:
96-
- `set -euo pipefail`
97-
- define default version sets from env vars:
98-
- `MYSQL_VERSIONS` defaulting to at least `8.0 8.4`
99-
- `POSTGRES_VERSIONS` reserved for subissue #1525-08
100-
- run pre-checks once (`cargo check --workspace --all-targets`)
101-
- run protocol/configuration tests once
102-
- run SQLite driver tests once
103-
- loop MySQL versions: `docker pull mysql:<version>`, then run MySQL driver tests with
104-
`TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=1` and
105-
`TORRUST_TRACKER_CORE_MYSQL_DRIVER_IMAGE_TAG=<version>`
106-
- print a clear heading for each backend/version before executing tests
107-
- fail fast on first failure with the failing backend/version visible in logs
108-
- keep script complexity intentionally low; avoid re-implementing test logic already in test
109-
functions
110-
- Replace the current single MySQL `database` step in `.github/workflows/testing.yaml` with
111-
execution of the new script.
95+
- Add a dedicated `database-compatibility` workflow job (between unit and e2e) with matrix values for MySQL versions:
96+
- include matrix values for at least `8.0` and `8.4`
97+
- run `cargo test -p bittorrent-tracker-core --features db-compatibility-tests run_mysql_driver_tests -- --nocapture`
98+
- set `TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=true`
99+
- set `TORRUST_TRACKER_CORE_MYSQL_DRIVER_IMAGE_TAG=<version>`
100+
- keep the test logic in Rust; use workflow matrix for version fan-out
101+
- Replace the current single MySQL `database` step in `.github/workflows/testing.yaml` with a
102+
dedicated `database-compatibility` job.
112103

113104
Acceptance criteria:
114105

115106
- [ ] DB image version injection is supported via `TORRUST_TRACKER_CORE_MYSQL_DRIVER_IMAGE_TAG`
116107
(and a reserved `POSTGRES` equivalent for subissue #1525-08).
117-
- [ ] `contrib/dev-tools/qa/run-db-compatibility-matrix.sh` exists and runs successfully.
118-
- [ ] The script exercises SQLite and at least two MySQL versions by default.
108+
- [ ] `database-compatibility` workflow job runs successfully for each configured MySQL version.
109+
- [ ] The workflow matrix exercises at least two MySQL versions by default.
119110
- [ ] Failures identify the backend/version combination that broke.
120-
- [ ] The `database` job step in `.github/workflows/testing.yaml` runs the matrix script instead
121-
of a single-version MySQL command.
122-
- [ ] The script structure allows PostgreSQL to be added in subissue #1525-08 without a redesign.
111+
- [ ] The dedicated `database-compatibility` job in `.github/workflows/testing.yaml` replaces the
112+
old single-version MySQL command.
113+
- [ ] The workflow matrix structure allows PostgreSQL to be added in subissue #1525-08 without a
114+
redesign.
123115
- [ ] Tests do not hard-code host ports; `testcontainers` assigns random ports automatically.
124116
- [ ] All containers started by tests are removed unconditionally on test completion or failure.
125117

126118
### 2) Document the workflow
127119

128120
Steps:
129121

130-
- Document the local invocation command for the matrix script.
131-
- Document that the CI `database` step runs the same script.
122+
- Document the local invocation command for the compatibility test using explicit feature + env
123+
vars.
124+
- Document that CI runs the same test through the `database-compatibility` workflow job matrix.
132125

133126
Acceptance criteria:
134127

135-
- [ ] The matrix script is documented and runnable without ad hoc manual steps.
128+
- [ ] The compatibility test command is documented and runnable without ad hoc manual steps.
136129

137130
## Out of Scope
138131

@@ -145,13 +138,13 @@ Acceptance criteria:
145138

146139
- [ ] `cargo test --workspace --all-targets` passes.
147140
- [ ] `linter all` exits with code `0`.
148-
- [ ] The matrix script has been executed successfully in a clean environment; a passing run log
149-
is included in the PR description.
141+
- [ ] The `database-compatibility` workflow job has been executed successfully in a clean
142+
environment; a passing run log is included in the PR description.
150143

151144
## References
152145

153146
- EPIC: #1525
154147
- Reference PR: #1695
155148
- Reference implementation branch: `josecelano:pr-1684-review` — see EPIC for checkout
156149
instructions (`docs/issues/1525-overhaul-persistence.md`)
157-
- Reference script: `contrib/dev-tools/qa/run-db-compatibility-matrix.sh`
150+
- Reference job: `.github/workflows/testing.yaml` `database-compatibility`

packages/tracker-core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ repository.workspace = true
1313
rust-version.workspace = true
1414
version.workspace = true
1515

16+
[features]
17+
default = [ ]
18+
db-compatibility-tests = [ ]
19+
1620
[dependencies]
1721
aquatic_udp_protocol = "0"
1822
bittorrent-primitives = "0.1.0"

packages/tracker-core/src/databases/driver/mysql.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl Database for Mysql {
345345
}
346346
}
347347

348-
#[cfg(test)]
348+
#[cfg(all(test, feature = "db-compatibility-tests"))]
349349
mod tests {
350350
use std::sync::Arc;
351351

@@ -379,7 +379,9 @@ mod tests {
379379

380380
impl StoppedMysqlContainer {
381381
async fn run(self, config: &MysqlConfiguration) -> Result<RunningMysqlContainer, Box<dyn std::error::Error + 'static>> {
382-
let container = GenericImage::new("mysql", "8.0")
382+
let image_tag = std::env::var("TORRUST_TRACKER_CORE_MYSQL_DRIVER_IMAGE_TAG").unwrap_or_else(|_| "8.0".to_string());
383+
384+
let container = GenericImage::new("mysql", image_tag.as_str())
383385
.with_exposed_port(config.internal_port.tcp())
384386
// todo: this does not work
385387
//.with_wait_for(WaitFor::message_on_stdout("ready for connections"))

0 commit comments

Comments
 (0)