Skip to content

Move redis container initialization to test utils#507

Merged
DanGould merged 2 commits intopayjoin:masterfrom
spacebear21:test-utils-redis
Jan 25, 2025
Merged

Move redis container initialization to test utils#507
DanGould merged 2 commits intopayjoin:masterfrom
spacebear21:test-utils-redis

Conversation

@spacebear21
Copy link
Copy Markdown
Collaborator

@spacebear21 spacebear21 commented Jan 23, 2025

Follow-up to #484 to move redis initialization to TestServices as well.

The first commit cleans up dev-dependencies from payjoin and payjoin-cli now that those dependencies are pulled in via the payjoin-test-utils crate.

Relatedly, I noticed that we initialize a tracing subscriber in a every test but don't really seem to be using tracing much, instead using log::debug in most places. Is there a reason to keep using tracing in tests or should we just remove that dependency too and use log instead?

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jan 23, 2025

Pull Request Test Coverage Report for Build 12958602475

Details

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 78.641%

Totals Coverage Status
Change from base Build 12957441139: 0.04%
Covered Lines: 3645
Relevant Lines: 4635

💛 - Coveralls

@spacebear21
Copy link
Copy Markdown
Collaborator Author

CI failing for MSRV due to testcontainers dependencies not supported upon upgrading to the latest version. @DanGould what's your process for this kind of thing? Should I just try downgrading testcontainers to the highest version that still compiles?

@spacebear21 spacebear21 requested a review from DanGould January 23, 2025 23:36
@DanGould
Copy link
Copy Markdown
Contributor

I look at crates.io/crates/redis to see which version is msrv compliant

Then I think I'd pin redis https://crates.io/crates/redis/0.23.3 with listed msrv 1.63 via Cargo-minimal.lock by cargo update -p redis --precise 0.23.3

These dependencies now live in `payjoin-test-utils`
@spacebear21 spacebear21 marked this pull request as draft January 24, 2025 19:32
@spacebear21 spacebear21 marked this pull request as ready for review January 24, 2025 22:22
testcontainers-modules is upgraded to the highest version that supports
rust 1.63.
@spacebear21
Copy link
Copy Markdown
Collaborator Author

spacebear21 commented Jan 24, 2025

I downgraded testcontainers to the highest version that still supported our MSRV. Unfortunately it doesn't support the cleaner Redis::start() syntax, so we still need to explicitly initialize docker. To prevent the docker client from being dropped during tests' execution we use Box::leak(), which looks kind of scary but should be fine when used only for testing.

Copy link
Copy Markdown
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

I've got nits which may or may not be follow ups. This looks great. Keeps getting cleaner.

pub struct TestServices {
cert_key: (Vec<u8>, Vec<u8>),
#[allow(dead_code)]
redis: (u16, Container<'static, Redis>),
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.

Perhaps add a docstring comment /// redis is an implicit dependency of directory [on the default port] to justify the #[allow(dead_code)] or otherwise set PJ_DB_HOST explicitly from redis's port info

}

// generates or gets a DER encoded localhost cert and key.
/// generates or gets a DER encoded localhost cert and key.
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.

super nit to prefer imperative (i.e. "generate") verbs in docstrings.

@DanGould
Copy link
Copy Markdown
Contributor

DanGould commented Jan 25, 2025

re:

I noticed that we initialize a tracing subscriber in a every test but don't really seem to be using tracing much, instead using log::debug in most places. Is there a reason to keep using tracing in tests or should we just remove that dependency too and use log instead?

We can easily convert log::x to tracing::x to take advantage of tracing's additional context. There's also the tracing-log crate to have dependency log::x handled as tracing::x calls.

I feel like tracing calls would be especially useful for payment processors depending on payjoin, like bria, since they depend heavily on structured logging, but I have to admit I'm green to the ins-and-outs of a well maintained system of structured logging.

I thought we should take advantage of tracing's structured logs in payjoin-directory, ohttp-relay, and payjoin-cli to provide structured logging for downstream users. It gives way more context across closure boundaries and with async, and the logs can be filtered dynamically. I figured this would be good for debugging and uptime monitoring in particular, but I do wonder if it's at odds with our goals for privacy. We're certainly not taking advantage of it yet. tracing lets us provide the kind of polish I'd like our actual kit to have post-1.0. If we figure out how to do that I reckon it makes sense to do in tests too.

Is it overly complex in tests? We're definitely not using it to leverage what we print in CI vs local. hard to say. @0xBEEFCAF3 @nothingmuch any comment on where we should be using structured logs

@DanGould DanGould merged commit 04eb29e into payjoin:master Jan 25, 2025
DanGould added a commit that referenced this pull request Jan 25, 2025
follow up for the prior test-utils redis abstractions at #507

See: #507 (review)
node-smithxby72w added a commit to node-smithxby72w/rust-payjoin that referenced this pull request Sep 28, 2025
follow up for the prior test-utils redis abstractions at #507

See: payjoin/rust-payjoin#507 (review)
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