diff options
author | Vishal Telangre <the@vishaltelangre.com> | 2019-05-05 11:25:26 +0530 |
---|---|---|
committer | Vishal Telangre <the@vishaltelangre.com> | 2019-05-10 20:16:17 +0530 |
commit | 93b652affbed41bce568a0fac4ca7b56aa3b691f (patch) | |
tree | ade38e50711efc2d8476a56e99179bb13107408d /activesupport/test | |
parent | 669b52d2965f50f1f3f99f1c54677a328191c69d (diff) | |
download | rails-93b652affbed41bce568a0fac4ca7b56aa3b691f.tar.gz rails-93b652affbed41bce568a0fac4ca7b56aa3b691f.tar.bz2 rails-93b652affbed41bce568a0fac4ca7b56aa3b691f.zip |
Introduce 'ActiveSupport::Notifications::Fanout::Subscribers::MonotonicTimed' and 'ActiveSupport::Notifications::monotonic_subscribe'
Also, change the signature of ‘ActiveSupport::Notifications::Fanout#subscribe’ to accept optional ‘monotonic’ boolean argument. Then initialize either a ‘Timed’ or ‘MonotonicTimed’ subscriber based on the value of ‘monotonic’ parameter.
Introduce ‘ActiveSupport::Notifications::monotonic_subscribe’ method
Also, provision ‘ActiveSupport::Notifications::subscribed’ to optionally accept ‘monotonic’ boolean argument.
Update documentation for ActiveSupport::Notifications
Add tests
Update guides documentation under the 'Active Support Instrumentation' chapter
Incorporate feedback: use optional keyword argument to specify optional 'monotonic' option to 'subscribed' method
Fix a typo
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/notifications_test.rb | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index d3c660a014..3b98749f1b 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -62,6 +62,38 @@ module Notifications end end + class TimedAndMonotonicTimedSubscriberTest < TestCase + def test_subscribe + event_name = "foo" + class_of_started = nil + class_of_finished = nil + + ActiveSupport::Notifications.subscribe(event_name) do |name, started, finished, unique_id, data| + class_of_started = started.class + class_of_finished = finished.class + end + + ActiveSupport::Notifications.instrument(event_name) + + assert_equal [Time, Time], [class_of_started, class_of_finished] + end + + def test_monotonic_subscribe + event_name = "foo" + class_of_started = nil + class_of_finished = nil + + ActiveSupport::Notifications.monotonic_subscribe(event_name) do |name, started, finished, unique_id, data| + class_of_started = started.class + class_of_finished = finished.class + end + + ActiveSupport::Notifications.instrument(event_name) + + assert_equal [Float, Float], [class_of_started, class_of_finished] + end + end + class SubscribedTest < TestCase def test_subscribed name = "foo" @@ -95,6 +127,42 @@ module Notifications ensure ActiveSupport::Notifications.notifier = old_notifier end + + def test_timed_subscribed + event_name = "foo" + class_of_started = nil + class_of_finished = nil + callback = lambda do |name, started, finished, unique_id, data| + class_of_started = started.class + class_of_finished = finished.class + end + + ActiveSupport::Notifications.subscribed(callback, event_name) do + ActiveSupport::Notifications.instrument(event_name) + end + + ActiveSupport::Notifications.instrument(event_name) + + assert_equal [Time, Time], [class_of_started, class_of_finished] + end + + def test_monotonic_timed_subscribed + event_name = "foo" + class_of_started = nil + class_of_finished = nil + callback = lambda do |name, started, finished, unique_id, data| + class_of_started = started.class + class_of_finished = finished.class + end + + ActiveSupport::Notifications.subscribed(callback, event_name, monotonic: true) do + ActiveSupport::Notifications.instrument(event_name) + end + + ActiveSupport::Notifications.instrument(event_name) + + assert_equal [Float, Float], [class_of_started, class_of_finished] + end end class UnsubscribeTest < TestCase @@ -317,7 +385,6 @@ module Notifications assert_equal 0, event.cpu_time end - def test_events_consumes_information_given_as_payload event = event(:foo, Concurrent.monotonic_time, Concurrent.monotonic_time + 1, random_id, payload: :bar) assert_equal Hash[payload: :bar], event.payload |