Skip to content

DRY up payjoin-mailroom tests #1944

Open

Description

@DanGould

This helper seems kinda selective for just the newly added test, when there are already existing tests with shared code that could be refactored as well.

Originally posted by @spacebear21 in #1941 (comment)

Activity

  1. unrealtim-tech commented on Oct 9, 2026

    @unrealtim-tech

    Hi maintainer, I would love to pick this up, could you assign this to me

  2. Christopherdominic commented on Oct 13, 2026

    @Christopherdominic
    Contributor

    I'd like to work on this.

    Looking through payjoin-mailroom/src/lib.rs, I noticed duplicated setup in the metrics tests, along with some shared setup across the service tests.

    I'm thinking of extracting reusable test fixtures for the common configuration and app setup, while keeping the test-specific behavior and assertions unchanged.

    Would that be a reasonable scope for this issue? @DanGould

  3. DanGould commented on Oct 13, 2026

    @DanGould
    MemberAuthor

    @Christopherdominic may you be a bit more specific about what'd be shared and where the fixtures and "configuration" (what configuration) would live? I want to get this one nailed down so the actual PR review only has to happen once, and it's pretty far off of our mainline path so hoping if you pick it up you can apply some good taste to whatever bot output helps clean this up.

  4. Christopherdominic commented on Oct 14, 2026

    @Christopherdominic
    Contributor

    Thanks for the feedback. I took another look at payjoin-mailroom/src/lib.rs, and here's the specific scope I have in mind.

    I'd keep the helpers local to the existing #[cfg(test)] mod tests in src/lib.rs, rather than introducing a separate fixtures module.

    1. Configuration: Reuse the existing test_config(storage_dir) helper, which creates a Config with an ephemeral listener address ([::]:0), temporary storage directory, 2-second timeout, and no optional configuration. Both metrics tests currently construct this same Config manually.

    2. Metrics setup: Extract a small async helper, something like metrics_test_app(), shared by middleware_records_metrics and middleware_bounds_endpoint_labels_in_metrics. It would create the in-memory metric exporter/provider, initialize the directory and relay services, and build the Axum app. It would return the app, provider, and exporter so each test can make its own requests and inspect its own metrics.

    3. TLS service tests: Keep start_service() as the shared service-startup helper for self_loop_request_is_rejected and cross_instance_request_is_accepted. I don't plan to merge it with health_status(), since the latter specifically tests access-control behavior across HTTP and HTTPS.

    The refactor would be limited to test setup in payjoin-mailroom/src/lib.rs. No changes to production code, assertions, or feature behavior. I'd run the mailroom tests with default and all features, plus formatting and Clippy.

    The goal is to remove actual duplication without introducing a generic fixture framework or unnecessary abstractions.

    Does that sound like the right scope before I start implementing it? @DanGould

    AI disclosure: I used AI assistance to inspect the duplicated setup and refine this proposal; I'll review the implementation myself.

  5. Christopherdominic commented on Nov 5, 2026

    @Christopherdominic
    Contributor

    @DanGould following up on the scope above: helpers stay local to the existing #[cfg(test)] mod tests in payjoin-mailroom/src/lib.rs, the metrics tests reuse test_config, and one shared metrics setup helper serves both metrics tests, with no new fixtures module. Does that match what you had in mind? I'll hold off on the PR until it's agreed so review only has to happen once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions