Skip to content

test(tracker-core): [#2902] cover the constructors of the MySQL and PostgreSQL drivers - #3036

Merged
josecelano merged 4 commits into
torrust:developfrom
josecelano-bot:2902-1347-add-tests-tracker-core-server-drivers
Nov 25, 2026
Merged

josecelano merged 4 commits into
torrust:developfrom
josecelano-bot:2902-1347-add-tests-tracker-core-server-drivers

Conversation

@josecelano-bot

@josecelano-bot josecelano-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Related to #2902

Slice S3 of #2902: the MySQL and PostgreSQL drivers of packages/tracker-core. It adds six unit tests, fixes two documentation commands and records why almost nothing else can be tested without a server. No production code changes.

Scope decision (Q8). I measured an unreachable endpoint first: Mysql::new("mysql://u:[email protected]:1/db") builds a lazy pool, and the first store call fails with ConnectionError { source: PoolTimedOut } after 30.0 s, the fixed sqlx acquire timeout of the pool options the drivers use. Q3 keeps Docker-free tests only if they are fast and not flaky, and a shorter timeout needs a production change, so the maintainer chose instant tests only. A malformed URL fails at once, and a well-formed one builds the pool without connecting.

Ledger rows File Decision
18 and 23 mysql/mod.rs, postgres/mod.rs the constructor: a malformed URL and a port that is not a number give a connection error of the driver's own kind; a well-formed URL builds a lazy pool without connecting (3 tests per driver, under a millisecond)
19-22 and 24-27 the auth-key, schema-migrator, torrent-metrics and whitelist files of both drivers no change: every executable line talks to the database, so a Docker-free test would wait 30 s; db-compatibility.yaml owns them

The setup.rs arms for the two drivers also stay untested here: the URL is built from typed fields and percent-encoded, so a configuration cannot produce one that fails to parse, and the arms can only fail after the 30 s timeout.

A first draft of the constructor tests had a case "a URL of another driver"; it was wrong (the MySQL parser accepts a postgresql:// URL and the PostgreSQL parser a mysql:// one), so it became "a port that is not a number". The plan records this.

Documentation (Q2). The README of tracker-core and packages/AGENTS.md gave TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=true cargo test ..., which omits --features db-compatibility-tests (without it the gated module is not compiled and nothing runs) and names only MySQL. Both now give the commands of the db-compatibility workflow for both drivers; the README also says that a run without the variable reports the suites as passed. The visible skip and the driver coverage in the published report stay with the separate issue of Q2.

Coverage of tracker-core (stable Rust 1.100.0, cargo-llvm-cov 0.9.1, against the develop base b81e4512e): unit-only lines 87.13% to 87.36% (287 unit tests, 281 on the base), aggregate 87.13% to 87.38%. The aggregate counts five more lines than the unit-only run in each of the two files with identical regions and functions; this is recorded and was not investigated further. Details: coverage-evidence.md, section "Slice Measurements".

Validation: cargo test -p torrust-tracker-core --all-features (287 unit, 15 integration and 18 other tests), cargo clippy -p torrust-tracker-core --all-targets --all-features, cargo +nightly fmt --all -- --check, cargo machete --with-metadata, the pre-commit gate on every commit and the repository's pre-push checks on push. The six mutants (three per driver) are each killed; the plan has the table.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added coverage for MySQL and PostgreSQL connection setup, including malformed URLs and construction without an immediate database connection.
  • Documentation
    • Clarified how to run the MySQL and PostgreSQL compatibility test suites, including their requirements and coverage commands.
    • Updated testing progress and coverage records for the database drivers.

josecelano-bot and others added 3 commits November 24, 2026 16:56
…L and PostgreSQL drivers

A malformed URL gives a connection error of the driver's own kind, and a well-formed one builds a
lazy pool without connecting. Unreachable-endpoint tests are not added: the pool takes 30 s to give
up, measured on 2026-11-24. The other server-driver files stay with db-compatibility.yaml.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…in the driver-test commands

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d16834d4-6a08-4dc5-9f59-8a6e269fa567
Commits

Reviewing files that changed from the base of the PR and between cfebf2e and 8fb5e11.

Files selected for processing: 1

  • docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md

No actionable comments were generated in the recent review.

Walkthrough

This change adds MySQL and PostgreSQL driver constructor tests, updates commands for running the driver suites, and records S3 coverage results and progress in the project documentation.

Changes: MySQL and PostgreSQL driver tests

Layer / File(s) Summary
Constructor test cases
packages/tracker-core/src/databases/driver/mysql/mod.rs, packages/tracker-core/src/databases/driver/postgres/mod.rs, docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/databases-server-drivers-tests.md
Adds tests that verify malformed URLs return driver-specific connection errors and valid URLs construct drivers without connecting. The test plan records the cases and validation.
Test and coverage commands
packages/AGENTS.md, packages/tracker-core/README.md
Documents opt-in test and coverage commands for both drivers, including the compatibility feature and environment variables.
S3 progress and coverage records
docs/issues/open/1347-overhaul-packages-testing/EPIC.md, docs/issues/open/2902-1347-add-tests-tracker-core/*
Records S3 completion details and updates aggregate, unit-only, and scope-comparison coverage results.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Other

Possibly related issues

Suggested reviewers: josecelano

Merge Risk: Minimal · previous review cfebf

This change adds Docker-free constructor tests and updates documentation, with no runtime behavior change. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test(tracker-core) scope, the issue number #2902, and the constructors of the MySQL and PostgreSQL drivers. The changeset adds constructor unit tests for both drivers in their mod.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test(tracker-core) scope, the issue number #2902, and the constructors of the MySQL and PostgreSQL drivers. The changeset adds constructor unit tests for both drivers in their mod.rs files and updates the related docs, README, and AGENTS.md. The title matches the main change. It omits the documentation and coverage updates, which is expected. Length is 86 characters, which is within a normal single-line title.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 66e5527a-182c-40dd-97a9-444a194570b3
Commits

Reviewing files that changed from the base of the PR and between 78c1b16 and cfebf2e.

Files selected for processing: 8

  • docs/issues/open/1347-overhaul-packages-testing/EPIC.md
  • docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md
  • docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md
  • docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/databases-server-drivers-tests.md
  • packages/AGENTS.md
  • packages/tracker-core/README.md
  • packages/tracker-core/src/databases/driver/mysql/mod.rs
  • packages/tracker-core/src/databases/driver/postgres/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Adds six constructor tests for the MySQL and PostgreSQL drivers without changing production code.

  • MySQL and PostgreSQL constructors now have fast URL checks.
  • Both driver suites now have feature-enabled commands in the testing guides.

No actionable issues were found in the latest changes or the full-PR rules check.

Reviews (2) · Last reviewed commit: "docs(issues): [#2902] record the S3 pull..." · Reviewed by Greptile

@josecelano

Copy link
Copy Markdown
Member

ACK 8fb5e11

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 8fb5e1181dc6a07642931cc1509ac1dc1410e2ef. Recomputed from the bytes at this head, against the merge base b81e4512e; git merge-tree against develop d89ab84bd writes a clean tree with no conflict, and no file this change touches has moved on develop since the merge base.

Process. A test-coverage slice, governed by write-unit-test, the issue's per-file workflow and plan guidance (ISSUE.md, test-refactor-plans/README.md), commit-changes and open-pull-request. The plan has every required section; ledger, slice row, measurement, EPIC rows and logs are updated; the description uses Related to, as the slice rules require. Gaps: F1, F2.

The change against its claim. Both constructors map a from_str failure through (e, DRIVER), which databases/error.rs turns into ConnectionError for Configuration; both inputs fail in the URL parser, and connect_lazy_with does no I/O but spawns a maintenance task, hence #[tokio::test]. Production code is unchanged, so the mutants are the guard: by reading, each test fails under its named mutation. The new commands match db-compatibility.yaml, and the skip-passes sentence matches the early return Ok(()) of both suites. Every percentage and delta in the evidence table, the EPIC rows and the plan recomputes; the setup.rs 119-128 reference and the percent-encoding claim hold.

Consistency. All 126 relative links, anchors and frontmatter paths in the six changed Markdown files resolve; nothing is moved; the dictionary is unchanged and every added word already occurs in the tree. Two records lag: the S2 row (F3) and the comments by the new modules (F4).

Hygiene. Four commits with Conventional subjects in the [#2902] form the slice rules give; the one body matches its diff; author equals committer. Each commit carries an attribution footer, which no rule in the tree forbids (the provenance discussion has no Outcome, and a discussion is not a rule). git diff --check is clean, the commit-id check prints nothing, and the closing-keyword pattern matches nothing in the title, description or folded messages.

Findings. Minor: F1 plan register row, F2 unrecorded per-file deviation, F3 stale S2 row. Nit: F4 wrong workflow in comments, F5 README sentence. None blocks.

Checked, no finding. The Driver import (as in stored_key_tests); the missing // Arrange (recorded in the plan); no audit record is due, as no comment asks for a reply.

Checks

On the loop's compute node at this head, against the merge base b81e4512e (receipt server-gates-kranich-1419): the repository's pre-commit gate and lint roster exit 0 (314 s wall). This pull request has no review audit record, so there was nothing for the audit validator to check. In the per-PR target directory, with every workspace crate recompiled at this head, cargo test --workspace passes 4678 tests with 0 failed and 5 ignored across 136 binaries (566 s wall), cargo clippy --workspace --all-targets --all-features -- -D warnings is clean (30 s wall), and cargo deny check exits 5 with no error outside the set develop already has (464 errors; the base's lockfile replaced torrust-located-error with source-location-check, which removes one license rejection). Checked against the bytes at posting: the Plans table in docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md ends at row 17 (line 44) and line 46 says "Add a row when a plan is created", while the new plan databases-server-drivers-tests.md has no row, as F1 says. The head was confirmed with git ls-remote before posting. GitHub checks at this head at posting time: "Publish (Development): completed/skipped; Publish (Release): completed/skipped; Context: completed/success; Package Coverage Regression: completed/success; Package Coverage (torrust-tracker-http-core): completed/success; Package Coverage (torrust-tracker-core): completed/success; Package Coverage (torrust-tracker-test-helpers): completed/success; Database Compatibility PostgreSQL (15): completed/success; Database Compatibility PostgreSQL (16): completed/success; Database Compatibility PostgreSQL (17): completed/success; Database Compatibility PostgreSQL (14): completed/success; Database Compatibility MySQL (8.4): completed/success; Database Compatibility MySQL (8.0): completed/success; Docker E2E: completed/skipped; Docs Lint: completed/success; Workspace Packaging: completed/success; Shipped Features: completed/success; Unit (stable): completed/success; Documented Clippy Allows: completed/success; Layer Boundary Bans: completed/success; Unit (nightly): completed/success; Source Locations: completed/success; Test (Docker) (release): completed/success; Build on windows-latest (nightly): completed/success; Build on ubuntu-latest (stable): completed/success; Build on windows-latest (stable): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on macos-latest (nightly): completed/success; Build on macos-latest (stable): completed/success; Generate Coverage Report: completed/success; Discover Package Coverage: completed/success; Persistence Benchmark SQLite3: completed/success; Persistence Benchmark MySQL: completed/success; Persistence Benchmark PostgreSQL: completed/success; CodeRabbit: completed/neutral; Greptile Review: completed/success". At posting, develop is d89ab84bd.


# Server Database Drivers Test Plan

Follow the shared [guidance](README.md). This plan covers ledger rows 18 to 27, slice S3: the MySQL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor][F1] The new plan has no row in the plan register of test-refactor-plans/README.md.

The guidance this line links says "Add a row when a plan is created", and its Plans table stops at sequence 17 (databases-driver-mod-and-traits-no-change.md) at this head; its Reconciliation section also asks for every plan state to be reconciled before final verification. Suggest adding row 18 for this plan, with its approval and result in the table's own form.


## Test Design

One test module per driver, always compiled (`#[cfg(test)]`, no feature), next to the existing gated one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor][F2] The slice departs from the issue's per-file rules without saying so.

ISSUE.md Commit Points gives T3 one commit per completed file and says "Never mix two source files", and Per-File Workflow gives each file one decision record, shared only by no-change rows. Here one record covers two test-producing files (mysql/mod.rs, postgres/mod.rs), and 9e965091d changes both. The two modules are identical, so nothing is hidden at this head, but a reader of the spec cannot tell whether the rule was waived. Suggest one sentence here or in the spec recording why the two drivers share a record and a commit.

| S1 | T2, then `statistics/`: `repository.rs`, `metrics.rs`, `persisted/mod.rs`, `persisted/downloads.rs`, `event/listener.rs`, `event/handler.rs`, `mod.rs` (the only area reached just by the integration binary) | 1-7 | `2902-1347-add-tests-tracker-core-statistics` | #2988 | DONE |
| S2 | The SQLite persistence boundary: `sqlite/{auth_key_store,torrent_metrics_store,whitelist_store,mod,schema_migrator}.rs`, `databases/{error,setup}.rs`, `error.rs`, the extraction of `parse_valid_until` and the row mapping (Q4, F2), plus the `databases/traits` and `driver/mod.rs` no-change decisions | 8-17 | `2902-1347-add-tests-tracker-core-sqlite` | #3009 | IN_PROGRESS |
| S3 | MySQL and PostgreSQL drivers: Docker-free error-path tests if non-flaky, otherwise no-change rows with the `db-compatibility` workflow as owner (Q3); the README and `packages/AGENTS.md` driver-test commands (Q2) | 18-27 | `2902-1347-add-tests-tracker-core-server-drivers` | TBD | TODO |
| S3 | MySQL and PostgreSQL drivers: Docker-free error-path tests if non-flaky, otherwise no-change rows with the `db-compatibility` workflow as owner (Q3); the README and `packages/AGENTS.md` driver-test commands (Q2) | 18-27 | `2902-1347-add-tests-tracker-core-server-drivers` | #3036 | IN_PROGRESS |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor][F3] The row above this one (line 301, outside the diff) still shows S2 as IN_PROGRESS.

The merge of its pull request #3009 is an ancestor of the merge base, and the Rules under this table say each PR updates the slice table. The previous slice made the same correction for S1 in docs(issues): [#2902] mark slice S1 done in the slice table. Suggest setting S2 to DONE in this change.

}

#[cfg(test)]
mod constructor_tests {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit][F4] Outside the diff, the comment above the gated suite (lines 201-202 here, and lines 182-183 of postgres/mod.rs) says it is invoked by the database-compatibility job of .github/workflows/testing.yaml.

That workflow has no such job at this head; db-compatibility.yaml runs both suites, as the README and the plan now say. The comment predates this change, but it sits beside the new module, and the slice's Q2 fix is about naming the right runner.

## Testing

Run tests including tests for MySQL driver:
Run tests including the tests of the MySQL driver (each driver suite needs the `db-compatibility-tests` feature, a container and its variable):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit][F5] This sentence still reads "Run tests including the tests of" the driver, but the command below it is now filtered to run_mysql_driver_tests, so it runs that one suite and none of the package's other tests.

Suggest wording it as running that driver's suite, as line 29 does for the other driver.

@da2ce7

da2ce7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

ACK 8fb5e11 — the six driver-constructor tests, the corrected driver-suite commands and the recomputed S3 coverage records were checked against the bytes at this head

@josecelano

Copy link
Copy Markdown
Member

ACK 8fb5e11

This branch was previously deployed

1 inactive deployment
coverage — 8fb5e118 Deployed Nov 24, 2026 by josecelano-bot via Generate Coverage Report #3463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants