Integrate blocking and multiplexing workers usage

This commit is contained in:
Thibault Jouan 2015-04-17 21:25:43 +00:00
parent fa03cd736a
commit 9ea43ee69a
7 changed files with 35 additions and 3 deletions

View File

@ -30,6 +30,7 @@ options:
-f, --run-control PATH specify alternate run control file -f, --run-control PATH specify alternate run control file
-r, --require PATH require ruby feature -r, --require PATH require ruby feature
-l, --layout LAYOUT specify layout -l, --layout LAYOUT specify layout
-w, --worker WORKER specify worker
``` ```

View File

@ -0,0 +1,9 @@
Feature: worker CLI option
Scenario: uses the blocking worker when `block' is given
When I run uhwm with option -v -w block
Then the output must match /work.+event.+block/i
Scenario: uses the multiplexing worker when `mux' is given
When I run uhwm with option -v -w mux
Then the output must match /work.+event.+mux/i

View File

@ -9,6 +9,7 @@ options:
-f, --run-control PATH specify alternate run control file -f, --run-control PATH specify alternate run control file
-r, --require PATH require ruby feature -r, --require PATH require ruby feature
-l, --layout LAYOUT specify layout -l, --layout LAYOUT specify layout
-w, --worker WORKER specify worker
eoh eoh
end end

View File

@ -77,6 +77,11 @@ module Uh
opts.on '-l', '--layout LAYOUT', 'specify layout' do |layout| opts.on '-l', '--layout LAYOUT', 'specify layout' do |layout|
@env.layout_class = self.class.const_get layout.to_sym @env.layout_class = self.class.const_get layout.to_sym
end end
opts.on '-w', Workers.types, '--worker WORKER',
'specify worker' do |worker|
@env.worker = worker.to_sym
end
end end
end end
end end

View File

@ -73,7 +73,9 @@ module Uh
end end
def run_until &block def run_until &block
manager.handle_pending_events until block.call worker.watch @manager
@env.log "Working events with `#{worker.class}'"
worker.work_events until block.call
end end
def terminate def terminate

View File

@ -176,6 +176,15 @@ module Uh
end end
end end
context 'with worker option' do
let(:arguments) { %w[-w mux] }
it 'assigns the worker type in the env' do
cli.parse_arguments!
expect(cli.env.worker).to eq :mux
end
end
context 'with invalid option' do context 'with invalid option' do
let(:arguments) { %w[--unknown-option] } let(:arguments) { %w[--unknown-option] }

View File

@ -144,10 +144,15 @@ module Uh
end end
describe '#run_until' do describe '#run_until' do
it 'tells the manager to handle events until given block is true' do it 'tells the worker to watch the manager' do
expect(runner.worker).to receive(:watch).with runner.manager
runner.run_until { true }
end
it 'tells the worker to work events until given block is true' do
block = proc { } block = proc { }
allow(block).to receive(:call).and_return(false, false, false, true) allow(block).to receive(:call).and_return(false, false, false, true)
expect(runner.manager).to receive(:handle_pending_events).exactly(3).times expect(runner.worker).to receive(:work_events).exactly(3).times
runner.run_until &block runner.run_until &block
end end
end end