Fix initial events handling for mux worker
* Rename `before_wait' worker callback to `before_watch'; * Setup `before_watch' callback in the runner, handling events with the manager; * Test the mux worker with a cucumber scenario.
This commit is contained in:
parent
e68d3fd6a3
commit
cd06f99e9f
15
features/workers/mux.feature
Normal file
15
features/workers/mux.feature
Normal file
@ -0,0 +1,15 @@
|
||||
Feature: multiplexing worker
|
||||
|
||||
Scenario: processes initial events
|
||||
Given uhwm is running with options -d -w mux
|
||||
Then the output must match /xevent/i at least 2 times
|
||||
|
||||
Scenario: processes generated events
|
||||
Given a run control file with:
|
||||
"""
|
||||
key(:f) { puts 'testing_worker_read' }
|
||||
"""
|
||||
And uhwm is running with options -d -w mux
|
||||
When I press the alt+f key 3 times
|
||||
And I quit uhwm
|
||||
Then the output must match /(testing_worker_read)/ exactly 3 times
|
@ -58,6 +58,9 @@ module Uh
|
||||
|
||||
def worker
|
||||
@worker ||= Workers.build(*(@env.worker)).tap do |w|
|
||||
w.before_watch do
|
||||
@manager.handle_pending_events
|
||||
end
|
||||
w.on_read do
|
||||
@manager.handle_pending_events
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ module Uh
|
||||
module WM
|
||||
module Workers
|
||||
class Base
|
||||
CALLBACKS = %w[before_wait on_timeout on_read on_read_next].freeze
|
||||
CALLBACKS = %w[before_watch on_timeout on_read on_read_next].freeze
|
||||
|
||||
def initialize **options
|
||||
@ios = []
|
||||
|
@ -8,7 +8,7 @@ module Uh
|
||||
end
|
||||
|
||||
def work_events
|
||||
@before_wait.call if @before_wait
|
||||
@before_watch.call if @before_watch
|
||||
if res = select(@ios, [], [], @timeout) then @on_read.call res
|
||||
else @on_timeout.call if @on_timeout end
|
||||
end
|
||||
|
@ -150,6 +150,11 @@ module Uh
|
||||
expect(runner.worker).to respond_to :work_events
|
||||
end
|
||||
|
||||
it 'setups the before_watch callback' do
|
||||
expect(runner.manager).to receive :handle_pending_events
|
||||
runner.worker.before_watch.call
|
||||
end
|
||||
|
||||
it 'setups the read callback' do
|
||||
expect(runner.manager).to receive :handle_pending_events
|
||||
runner.worker.on_read.call
|
||||
|
Loading…
x
Reference in New Issue
Block a user