Devel--Cover icon indicating copy to clipboard operation
Devel--Cover copied to clipboard

Cover with fork

Open sidey79 opened this issue 4 years ago • 6 comments

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?

sidey79 avatar Sep 09 '19 17:09 sidey79

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

verilog15 avatar Oct 17 '19 10:10 verilog15

No, i haven`t found a solution :(

sidey79 avatar Oct 17 '19 13:10 sidey79

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.

josch avatar Jan 07 '20 22:01 josch

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

sidey79 avatar Jan 07 '20 22:01 sidey79

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');
};

okurz avatar Dec 10 '20 20:12 okurz

@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.

pileswasp avatar Dec 16 '20 09:12 pileswasp