Skip to content

Commit

Permalink
Added test for the missing ::Async::Reactor.run.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jul 26, 2023
1 parent 0720377 commit 76c1301
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/slack-ruby-bot-server/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def start_from_database!
start_intervals!
end

def start_intervals!
::Async::Reactor.run do
def start_intervals!(&_block)
::Async::Reactor.run do |task|
@intervals.each_pair do |period, calls_with_options|
calls_with_options.each do |call_with_options|
call, options = *call_with_options
Expand All @@ -88,6 +88,7 @@ def start_intervals!
end
end
end
yield task if block_given?
end
end

Expand Down
15 changes: 5 additions & 10 deletions spec/slack-ruby-bot-server/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
let(:instance) { SlackRubyBotServer::Service.instance }
context 'without timers' do
it 'noop' do
Async::Reactor.run do |task|
instance.start_intervals!
instance.start_intervals! do |task|
task.stop
end
expect(instance.instance_variable_get(:@intervals).keys).to eq []
Expand Down Expand Up @@ -94,8 +93,7 @@
end
end
it 'sets up timers' do
Async::Reactor.run do |task|
instance.start_intervals!
instance.start_intervals! do |task|
task.sleep 3
task.stop
end
Expand All @@ -115,8 +113,7 @@
end
end
it 'does not abort all timers on failure of the first one' do
Async::Reactor.run do |task|
instance.start_intervals!
instance.start_intervals! do |task|
task.sleep 3
task.stop
end
Expand All @@ -132,8 +129,7 @@
end
end
it 'runs the timer once within 3 seconds' do
Async::Reactor.run do |task|
instance.start_intervals!
instance.start_intervals! do |task|
task.sleep 3
task.stop
end
Expand All @@ -148,8 +144,7 @@
end
end
it 'runs the timer exactly twice within 3 seconds' do
Async::Reactor.run do |task|
instance.start_intervals!
instance.start_intervals! do |task|
task.sleep 3
task.stop
end
Expand Down

0 comments on commit 76c1301

Please sign in to comment.