Use unique DB name for Postgres test fixture#164
Conversation
Reviewer's GuideThis PR enhances the PostgresTestDb fixture by generating unique per-test database names using UTC timestamps and updates the corresponding documentation for Mermaid validation and Rust testing fixtures. Class diagram for updated PostgresTestDb fixtureclassDiagram
class PostgresTestDb {
+String db_name
+new() PostgresTestDb
+connect() Connection
}
note for PostgresTestDb "db_name is now unique per test (e.g., includes UTC timestamp)"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce dynamic naming and explicit cleanup for embedded PostgreSQL test databases by generating a unique database name per test using a UUID. The embedded database is dropped during fixture cleanup. Documentation is updated to reflect these changes, and the Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test
participant Fixture as PostgresTestDb
participant Embedded as EmbeddedPg
participant Postgres as PostgreSQL
Test->>Fixture: Request test DB
Fixture->>Embedded: Start embedded Postgres
Embedded->>Postgres: Create DB with unique UUID name
Embedded->>Fixture: Return DB URL and name
Fixture->>Test: Provide DB connection
Note over Test,Fixture: Test executes using unique DB
Test->>Fixture: Test ends, cleanup
Fixture->>Postgres: DROP DATABASE <unique_name>
Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Gates Passed
6 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes - here's some feedback:
- Consider using a UUID or random suffix instead of just
timestamp_nanosto guarantee uniqueness even when multiple tests start within the same nanosecond. - Ensure that the dynamically created test databases are reliably dropped or cleaned up on panic or test suite exit to avoid orphaned databases consuming resources.
- You might extract the database‐naming logic into a configurable helper (e.g. allowing a custom prefix) to make it more reusable and clearer in intent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using a UUID or random suffix instead of just `timestamp_nanos` to guarantee uniqueness even when multiple tests start within the same nanosecond.
- Ensure that the dynamically created test databases are reliably dropped or cleaned up on panic or test suite exit to avoid orphaned databases consuming resources.
- You might extract the database‐naming logic into a configurable helper (e.g. allowing a custom prefix) to make it more reusable and clearer in intent.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Gates Passed
6 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
docs/mermaid-validation.md(1 hunks)docs/rust-testing-with-rstest-fixtures.md(1 hunks)test-util/Cargo.toml(1 hunks)test-util/src/lib.rs(6 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/mermaid-validation.md
[style] ~39-~39: Consider using a different verb for a more formal wording.
Context: ... error location are printed to help you fix the issue. If nixie is not found on ...
(FIX_RESOLVE)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: coverage
- GitHub Check: windows-build (sqlite)
🔇 Additional comments (5)
docs/rust-testing-with-rstest-fixtures.md (1)
1320-1326: Good additionThe new subsection clearly explains the UUID-based per-test database and its
cleanup behaviour.test-util/src/lib.rs (4)
92-96: Struct update looks sensibleStoring
db_namealongside the URL gives the cleanup code the information it
needs without changing external APIs.
157-166: Unique DB name generation ✔Using
test_<UUIDv4>guarantees uniqueness and stays inside Postgres’
identifier rules (<63 chars, starts with a letter). Good call.
300-305: Propagation ofdb_namePassing the database name up to the fixture ensures the Drop impl can clean up.
All fine here.
512-513: Pattern updateUsing
..in the destructure keeps the signature future-proof and avoids an
unused-field warning – good.
There was a problem hiding this comment.
Gates Passed
6 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Gates Failed
Prevent hotspot decline
(1 hotspot with Deep, Nested Complexity)
Enforce critical code health rules
(1 file with Deep, Nested Complexity)
Gates Passed
3 Quality Gates Passed
See analysis details in CodeScene
Reason for failure
| Prevent hotspot decline | Violations | Code Health Impact | |
|---|---|---|---|
| lib.rs | 1 rule in this hotspot | 9.10 → 8.55 | Suppress |
| Enforce critical code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| lib.rs | 1 critical rule | 9.10 → 8.55 | Suppress |
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Gates Passed
6 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
There was a problem hiding this comment.
Gates Passed
6 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
Summary
Testing
cargo clippy -- -D warningsRUSTFLAGS="-D warnings" cargo testcargo clippy --no-default-features --features postgres -- -D warnings(fails: could not compilepostgres-setup-unpriv)RUSTFLAGS="-D warnings" cargo test --no-default-features --features postgres(fails: could not compilepostgres-setup-unpriv)markdownlint '**/*.md'nixie **/*.mdhttps://chatgpt.com/codex/tasks/task_e_685299d37b00832283b9fa013c62b53a
Summary by Sourcery
Generate unique per-test database names for embedded Postgres fixtures and update documentation for mermaid validation and test fixtures.
Enhancements:
Documentation:
Summary by CodeRabbit
Documentation
New Features
Chores
uuidcrate for generating unique database names.