Skip to content

Include payjoin-cli in coverage reports #475

Closed

Description

@spacebear21

Coverage reports show 0% coverage for payjoin-cli (e.g. https://coveralls.io/builds/71695858). It should show coverage for payjoin-cli.

Activity

  1. spacebear21 commented on Jan 17, 2025

    @spacebear21
    CollaboratorAuthor

    I believe this is happening because the CLI is calling the payjoin-cli binary directly with a tokio Command.

    I see two potential solutions:

    1. Figure out a way to compile the payjoin-cli binary used by the tests, with coverage instrumentation explicitly enabled. I tried this approach to no avail.
    2. OR in the e2e tests, use direct function calls instead of binary execution. This would require splitting src/main.rs so that the logic lives in a src/lib.rs and main() just acts as a light wrapper around it (see rust docs on testing binary crates).
  2. nothingmuch commented on Jan 17, 2025

    @nothingmuch
    Contributor
    1. Figure out a way to compile the payjoin-cli binary used by the tests, with coverage instrumentation explicitly enabled. I tried this approach to no avail.

    Did this fail to build or fail to instrument?

    1. OR in the e2e tests, use direct function calls instead of binary execution. This would require splitting src/main.rs so that the logic lives in a src/lib.rs and main() just acts as a light wrapper around it (see rust docs on testing binary crates).

    At least on POSIX platforms this is possible in principle, but not sure if we can do it in the context of tokio. Before forking and directly invoking the function that main() would call if it was launched from the command line, instead of execing it as an external process, the child process's stdin and stdout can be replaced (using dup2) with a pipe pair (see tokio-pipe crate).

    However, exec replaces the child process image with the executed program, without calling it immediately after the child inherits the parent process memory and various OS resources. It's not clear to me from tokio-fork docs whether or not this is taken into account, so this might cause issues if the child process continues to try to execute the runtime/event loop, and would share resources such as file descriptors with the parent process, potentially interfering with the parent process, so this might be more trouble than it's worth, and this issue makes me pessimistic... (a tokio-fork crate exists, but docs are unclear)

  3. spacebear21 commented on Jan 17, 2025

    @spacebear21
    CollaboratorAuthor

    Did this fail to build or fail to instrument?

    It built successfully, just still showed no payjoin-cli coverage in the report.

  4. spacebear21 commented on Jan 19, 2025

    @spacebear21
    CollaboratorAuthor

    I finally got to the root of the issue after much debugging (thanks @nothingmuch for the assist!), and feel a bit silly for not noticing it earlier.

    The e2e test does run an instrumented build of payjoin-cli; the problem is that we explicitly kill the spawned child processes! This aborts the coverage files from generating.

    What we need is the ability to gracefully shutdown payjoin-cli using a signal handler, that we can then use in these tests instead of outright killing the processes.

  5. DanGould commented on Jan 20, 2025

    @DanGould
    Member

    Closed by #497 (but perhaps not completely because of the feature flag configuration @spacebear21 ? Please make a new issue or reopen and edit OP if this is still a concern)

    One thing I noticed is that payjoin-cli v1 is not covered, which is likely due to the missing _danger-local-https in contrib/coverage.sh for the v1 llvm-cov command. This can be addressed in a separate PR.

    #497 (review)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions