pjcj / Devel--Cover

Code coverage metrics for Perl
http://www.pjcj.net/perl.html
93 stars 88 forks source link

Cover with fork #244

Open sidey79 opened 5 years ago

sidey79 commented 5 years ago

Hi,

I'm using the Cover module to monitor test coverage of a application module written in perl.

The tests are running inside the application itself. The application forks a process just before a test is started. Therefor i start the inital perl process via the -MDevel:Cover switch.

From a process view this option is propagated to the child subprocesses.

But it looks like, that the subprocesses are not generating cover data.

Should this module work with forked subprocesses?

verilog15 commented 4 years ago

Hi @sidey79, Have you managed to solve this issue? I'm facing the same problem.

sidey79 commented 4 years ago

No, i haven`t found a solution :(

josch commented 4 years ago

Funnily, I'm having the opposite problem. Devel::Cover happily persists across fork() calls and causes massive slowdowns once an exec() is done in the child process. See https://stackoverflow.com/questions/59623927/how-do-i-disable-develcover-for-forked-child-processes

I wonder why Devel::Cover doesn't survive the fork() in your case.

sidey79 commented 4 years ago

I think it survives in my case also, but there seems to be correct no results witten to the database

okurz commented 3 years ago

What you can do is to call Devel::Cover::report() explicitly before terminating each spawned process if running with coverage analysis. This is what we do in one of the projects I participate in: https://github.com/os-autoinst/openQA/blob/c4c7e4dad37c6e20ada91772c939917383834e56/t/25-cache-service.t#L74 comparable to:

my $process = process sub {
    # some spawned process running code and eventually terminating …
    Devel::Cover::report() if Devel::Cover->can('report');
};
pileswasp commented 3 years ago

@sidey79 You say both "a process" and "subprocesses": are you trying to collect coverage data from multiple processes in parallel? Using App::Prove or App:ForkProve I set --jobs 1 or I get lots of deep recursion warnings and no coverage data out of tests run with Devel::Cover. It will combine data from multiple forked processes, just not simultaneously.