aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/notifications_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-07-20 17:07:18 +0200
committerJosé Valim <jose.valim@gmail.com>2010-07-20 17:07:18 +0200
commit9df9c4bac008ba94c37faff411368c33408faff8 (patch)
tree4aef79e09a0c98843132a5a8a1dae61c19d7b13e /activesupport/test/notifications_test.rb
parent51d2db0a63529cfe6e7d7d0c620f10235c63ffe4 (diff)
downloadrails-9df9c4bac008ba94c37faff411368c33408faff8.tar.gz
rails-9df9c4bac008ba94c37faff411368c33408faff8.tar.bz2
rails-9df9c4bac008ba94c37faff411368c33408faff8.zip
Add a test for elapsed and require missing benchmark file.
Diffstat (limited to 'activesupport/test/notifications_test.rb')
-rw-r--r--activesupport/test/notifications_test.rb30
1 files changed, 13 insertions, 17 deletions
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index 73c85be87c..41e8ca4ae7 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -11,14 +11,11 @@ module Notifications
@named_subscription = @notifier.subscribe("named.subscription") { |*args| @named_events << event(*args) }
end
- private
- def event(*args)
- ActiveSupport::Notifications::Event.new(*args)
- end
+ private
- def drain
- @notifier.wait
- end
+ def event(*args)
+ ActiveSupport::Notifications::Event.new(*args)
+ end
end
class UnsubscribeTest < TestCase
@@ -132,13 +129,10 @@ module Notifications
def test_instrument_returns_block_result
assert_equal 2, instrument(:awesome) { 1 + 1 }
- drain
end
def test_instrument_yields_the_paylod_for_further_modification
assert_equal 2, instrument(:awesome) { |p| p[:result] = 1 + 1 }
- drain
-
assert_equal 1, @events.size
assert_equal :awesome, @events.first.name
assert_equal Hash[:result => 2], @events.first.payload
@@ -154,15 +148,11 @@ module Notifications
1 + 1
end
- drain
-
assert_equal 1, @events.size
assert_equal :wot, @events.first.name
assert_equal Hash[:payload => "child"], @events.first.payload
end
- drain
-
assert_equal 2, @events.size
assert_equal :awesome, @events.last.name
assert_equal Hash[:payload => "notifications"], @events.last.payload
@@ -177,16 +167,22 @@ module Notifications
assert_equal "FAIL", e.message
end
- drain
assert_equal 1, @events.size
assert_equal Hash[:payload => "notifications",
:exception => ["RuntimeError", "FAIL"]], @events.last.payload
end
+ def test_elapsed
+ instrument(:something) do
+ sleep(0.001)
+ end
+
+ # Elapsed returns duration in ms
+ assert_in_delta 1, ActiveSupport::Notifications.instrumenter.elapsed, 100
+ end
+
def test_event_is_pushed_even_without_block
instrument(:awesome, :payload => "notifications")
- drain
-
assert_equal 1, @events.size
assert_equal :awesome, @events.last.name
assert_equal Hash[:payload => "notifications"], @events.last.payload