Skip to content

Commit

Permalink
Merge pull request #1358 from mbj/change/to-faster-signal
Browse files Browse the repository at this point in the history
Change to more efficient worker termination
  • Loading branch information
mbj authored Nov 21, 2022
2 parents cd67f8d + 25f9d8b commit 5b57790
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/mutant/parallel/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def stop
def finalize(status)
status.tap do
if status.done?
workers.each(&:signal)
workers.each(&:join)
threads.each(&:join)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/mutant/parallel/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ def call
self
end

def join
def signal
process.kill('TERM', pid)
self
end

def join
process.wait(pid)
self
end
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/mutant/parallel/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def apply
let(:raw_expectations) do
[
*super(),
{
receiver: worker_a,
selector: :signal
},
{
receiver: worker_b,
selector: :signal
},
{
receiver: worker_a,
selector: :join
Expand Down
35 changes: 30 additions & 5 deletions spec/unit/mutant/parallel/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ def apply

let(:raw_expectations) do
[
{
receiver: world.process,
selector: :kill,
arguments: ['TERM', pid]
},
{
receiver: world.process,
selector: :wait,
Expand All @@ -223,6 +218,36 @@ def apply
end
end

describe '#signal' do
let(:object) do
described_class.new(
connection: connection,
index: index,
pid: pid,
process: world.process,
**shared
)
end

def apply
object.signal
end

let(:raw_expectations) do
[
{
receiver: world.process,
selector: :kill,
arguments: ['TERM', pid]
}
]
end

it 'terminates and waits for process' do
verify_events { expect(apply).to be(object) }
end
end

describe '.start' do
let(:block) { ->(value) { value * 2 } }
let(:child_connection) { instance_double(Mutant::Pipe::Connection) }
Expand Down

0 comments on commit 5b57790

Please sign in to comment.