test/angelo/websocket_spec.rb in angelo-0.4.1 vs test/angelo/websocket_spec.rb in angelo-0.5.0
- old
+ new
@@ -12,14 +12,14 @@
wsh.init
wsh
end
action = (key.to_s + '_go').to_sym
Reactor.define_action action do |n|
- every(0.01){ terminate if Reactor.stop? }
Reactor.testers[key][n].go
end
Reactor.unstop!
+ $reactor.async.wait_for_stop
CONCURRENCY.times {|n| $reactor.async.__send__(action, n)}
sleep 0.01 * CONCURRENCY
yield
@@ -49,14 +49,14 @@
}
wsh.init
Reactor.testers[:tester] = wsh
Reactor.define_action :go do
- every(0.01){ terminate if Reactor.stop? }
Reactor.testers[:tester].go
end
Reactor.unstop!
+ $reactor.async.wait_for_stop
$reactor.async.go
500.times {|n| wsh.text "hi there #{n}"}
latch.wait
@@ -67,41 +67,41 @@
end
it 'responds on multiple websockets properly' do
latch = CountDownLatch.new CONCURRENCY * 500
- Reactor.testers[:wshs] = Array.new(CONCURRENCY).map do
+ Reactor.testers[:wshs] = Array.new CONCURRENCY do
wsh = websocket_helper '/'
wsh.on_message = ->(e) {
assert_match /hi there \d/, e.data
latch.count_down
}
wsh.init
wsh
end
Reactor.define_action :go do |n|
- every(0.01){ terminate if Reactor.stop? }
Reactor.testers[:wshs][n].go
end
Reactor.unstop!
+ $reactor.async.wait_for_stop
CONCURRENCY.times {|n| $reactor.async.go n}
sleep 0.01 * CONCURRENCY
- ActorPool.define_action :go do |n|
+ Actor.define_action :go do |n|
500.times {|x| Reactor.testers[:wshs][n].text "hi there #{x}"}
end
- CONCURRENCY.times {|n| $pool.async.go n}
+ CONCURRENCY.times {|n| $pool[n].async.go n}
latch.wait
Reactor.testers[:wshs].map &:close
Reactor.stop!
Reactor.testers.delete :wshs
Reactor.remove_action :go
- ActorPool.remove_action :go
+ Actor.remove_action :go
end
end
describe 'before blocks' do
@@ -125,14 +125,14 @@
latch.count_down
}
wsh.init
Reactor.testers[:tester] = wsh
Reactor.define_action :go do
- every(0.01){ terminate if Reactor.stop? }
Reactor.testers[:tester].go
end
Reactor.unstop!
+ $reactor.async.wait_for_stop
$reactor.async.go
latch.wait
Reactor.stop!
@@ -166,14 +166,14 @@
latch.count_down
}
wsh.init
Reactor.testers[:tester] = wsh
Reactor.define_action :go do
- every(0.01){ terminate if Reactor.stop? }
Reactor.testers[:tester].go
end
Reactor.unstop!
+ $reactor.async.wait_for_stop
$reactor.async.go
latch.wait
Reactor.stop!
@@ -284,11 +284,11 @@
it 'handles multiple contexts' do
latch = CountDownLatch.new CONCURRENCY
- Reactor.testers[:hmc] = Array.new(CONCURRENCY).map do
+ Reactor.testers[:hmc] = Array.new CONCURRENCY do
wsh = websocket_helper '/'
wsh.on_message = ->(e) {
wait_for_block[e]
latch.count_down
}
@@ -296,11 +296,11 @@
wsh
end
one_latch = CountDownLatch.new CONCURRENCY
- Reactor.testers[:hmc_one] = Array.new(CONCURRENCY).map do
+ Reactor.testers[:hmc_one] = Array.new CONCURRENCY do
wsh = websocket_helper '/one'
wsh.on_message = ->(e) {
wait_for_block[e]
one_latch.count_down
}
@@ -308,10 +308,10 @@
wsh
end
other_latch = CountDownLatch.new CONCURRENCY
- Reactor.testers[:hmc_other] = Array.new(CONCURRENCY).map do
+ Reactor.testers[:hmc_other] = Array.new CONCURRENCY do
wsh = websocket_helper '/other'
wsh.on_message = ->(e) {
wait_for_block[e]
other_latch.count_down
}