You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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).
This could work but currently the tests are setup to read and parse output from stdout which I'm not sure is possible without using tokio::process::Command.
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?
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)
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.
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.
Activity
spacebear21 commentedon Jan 17, 2025
I believe this is happening because the CLI is calling the payjoin-cli binary directly with a tokio
Command.I see two potential solutions:
payjoin-clibinary used by the tests, with coverage instrumentation explicitly enabled. I tried this approach to no avail.src/main.rsso that the logic lives in asrc/lib.rsand main() just acts as a light wrapper around it (see rust docs on testing binary crates).tokio::process::Command.nothingmuch commentedon Jan 17, 2025
Did this fail to build or fail to instrument?
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 ofexecing it as an external process, the child process's stdin and stdout can be replaced (usingdup2) with a pipe pair (see tokio-pipe crate).However,
execreplaces 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)spacebear21 commentedon Jan 17, 2025
It built successfully, just still showed no payjoin-cli coverage in the report.
spacebear21 commentedon Jan 19, 2025
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-cliusing a signal handler, that we can then use in these tests instead of outright killing the processes.DanGould commentedon Jan 20, 2025
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)
#497 (review)