Skip to content

Commit

Permalink
Make sure reactor is running while stopping
Browse files Browse the repository at this point in the history
The documentation says it should be like that.
  • Loading branch information
grddev committed Oct 29, 2015
1 parent c56d2d0 commit af6c6b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ione/io/io_reactor.rb
Expand Up @@ -124,7 +124,7 @@ def on_error(&listener)
# after {#stop} has been called, but false when the future returned by
# {#stop} completes.
def running?
@state == RUNNING_STATE
(state = @state) == RUNNING_STATE || state == STOPPING_STATE
end

# Starts the reactor. This will spawn a background thread that will manage
Expand Down
17 changes: 16 additions & 1 deletion spec/ione/io/io_reactor_spec.rb
Expand Up @@ -172,12 +172,27 @@ def fake_connected(connection)
reactor.stop.value.should equal(reactor)
end

it 'is not running after being stopped' do
it 'is not running after stop completed' do
reactor.start.value
reactor.stop.value
reactor.should_not be_running
end

it 'keeps running until stop completed' do
running_barrier = Queue.new
stop_barrier = Queue.new
selector.handler do
running_barrier.push(nil)
stop_barrier.pop
[[], [], []]
end
reactor.start.value
future = reactor.stop
running_barrier.pop
reactor.should be_running
stop_barrier.push(nil) until future.completed?
end

it 'closes all sockets' do
reactor.start.value
connection = reactor.connect('example.com', 9999, 5).value
Expand Down

0 comments on commit af6c6b9

Please sign in to comment.