I recently added simplecov to my project, and found if i wanted simplecov to track what Parallel was doing I had to override the Parallel.worker method to inject SimpleCov.start and a unique command name.
I ended up adding this whole overridden method to my .simplecov file:
module Parallel
def self.worker(job_factory, options, &block)
child_read, parent_write = IO.pipe
parent_read, child_write = IO.pipe
pid = Process.fork do
self.worker_number = options[:worker_number]
begin
# here begins my additions
SimpleCov.command_name "Parallel #{worker_number} #{Process.pid}"
SimpleCov.start
# here ends my additions
options.delete(:started_workers).each(&:close_pipes)
parent_write.close
parent_read.close
process_incoming_jobs(child_read, child_write, job_factory, options, &block)
ensure
child_read.close
child_write.close
end
end
child_read.close
child_write.close
Worker.new(parent_read, parent_write, pid)
end
end
I'd love a way to do this that was expected. (and I'd prefer that way be global rather than every Parrallel.each call.)
Do you have a preference/expectation for how one should do this? I'm happy to make a PR adding an option if you'd like
Perhaps someone could have in their .simplecov something like
Parallel.post_fork = -> {
SimpleCov.command_name "Parallel #{Process.pid}"
SimpleCov.start
}
and we add Parallel.post_fork&.call in the Process.worker method where i added my code?
Thanks :)
I recently added simplecov to my project, and found if i wanted simplecov to track what Parallel was doing I had to override the
Parallel.workermethod to inject SimpleCov.start and a unique command name.I ended up adding this whole overridden method to my .simplecov file:
I'd love a way to do this that was expected. (and I'd prefer that way be global rather than every
Parrallel.eachcall.)Do you have a preference/expectation for how one should do this? I'm happy to make a PR adding an option if you'd like
Perhaps someone could have in their .simplecov something like
and we add
Parallel.post_fork&.callin the Process.worker method where i added my code?Thanks :)