Integrate blocking and multiplexing workers usage
This commit is contained in:
parent
fa03cd736a
commit
9ea43ee69a
@ -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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
9
features/cli/worker.feature
Normal file
9
features/cli/worker.feature
Normal 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
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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] }
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user