Skip to content

Commit

Permalink
Add Ruby-3.3 Process.warmup
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Feb 1, 2024
1 parent 609318b commit db2dea2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# v0.11.28

* Fix CLI parsing issue where arguments given to `mutant environment` where silently ignored.
[#1416](https://github.com/mbj/mutant/pull/1416)
* [#1416](https://github.com/mbj/mutant/pull/1416)
Fix CLI parsing issue where arguments given to `mutant environment` where silently ignored.

* Change to report efficiency instead of overhead.
* [#1415](https://github.com/mbj/mutant/pull/1415)
Change to report efficiency instead of overhead.
Efficiency is defined by `killtime / runtime`.

[#1415](https://github.com/mbj/mutant/pull/1415)
* [#1413](https://github.com/mbj/mutant/pull/1413)

Add `Process.warmup` optimization for ruby-3.3+ which yields a noticable speed improvement.

# v0.11.27 2023-12-01

Expand Down
2 changes: 2 additions & 0 deletions lib/mutant/mutation/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def self.call(env)
def self.run_mutation_analysis(env)
reporter = reporter(env)

env.world.process_warmup

env
.record(:analysis) { run_driver(reporter, async_driver(env)) }
.tap { |result| env.record(:report) { reporter.report(result) } }
Expand Down
4 changes: 4 additions & 0 deletions lib/mutant/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@ def deadline(allowed_time)
def record(name, &block)
recorder.record(name, &block)
end

def process_warmup
process.warmup if process.respond_to?(:warmup)
end
end # World
end # Mutant
14 changes: 13 additions & 1 deletion spec/unit/mutant/mutation/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
let(:emit_mutation_worker_process_start) { instance_double(Proc) }
let(:env_result) { instance_double(Mutant::Result::Env) }
let(:reporter) { instance_double(Mutant::Reporter, delay: delay) }
let(:world) { fake_world }
let(:world) { instance_double(Mutant::World) }
let(:timer) { instance_double(Mutant::Timer) }

let(:env) do
instance_double(
Expand Down Expand Up @@ -55,6 +56,7 @@
end

before do
allow(world).to receive_messages(timer: timer)
allow(world.timer).to receive_messages(now: 1.0)
end

Expand All @@ -70,6 +72,11 @@ def apply
selector: :start,
arguments: [env]
},
{
receiver: world,
selector: :process_warmup,
arguments: []
},
{
receiver: env,
selector: :record,
Expand Down Expand Up @@ -147,6 +154,11 @@ def apply
selector: :start,
arguments: [env]
},
{
receiver: world,
selector: :process_warmup,
arguments: [],
},
{
receiver: env,
selector: :record,
Expand Down
39 changes: 39 additions & 0 deletions spec/unit/mutant/world_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,43 @@ def apply
end
end
end

describe '#process_warmup' do
let(:process) { double(Process) }

subject { super().with(process: process) }

def apply
subject.process_warmup
end

before do
allow(process).to receive_messages(
respond_to?: respond_to?,
warmup: process
)
end

context 'when process supports warmup' do
let(:respond_to?) { true }

it 'performs warmup' do
apply

expect(process).to have_received(:respond_to?).with(:warmup).ordered
expect(process).to have_received(:warmup).ordered
end
end

context 'when process supports warmup' do
let(:respond_to?) { false }

it 'performs warmup' do
apply

expect(process).to have_received(:respond_to?).with(:warmup)
expect(process).to_not have_received(:warmup)
end
end
end
end

0 comments on commit db2dea2

Please sign in to comment.