提交 5988b87c 编写于 作者: J José Valim

Added parent_of? method to help tracing events.

上级 11f9f556
......@@ -112,6 +112,11 @@ def initialize(name, payload)
@result = @payload.delete(:result)
@duration = @payload.delete(:duration)
end
def parent_of?(event)
start = (self.time - event.time) * 1000
start <= 0 && (start + self.duration >= event.duration)
end
end
# This is a default queue implementation that ships with Orchestra. It
......
......@@ -9,20 +9,36 @@ def clear
class OrchestraEventTest < Test::Unit::TestCase
def test_events_are_initialized_with_name_and_payload
event = ActiveSupport::Orchestra::Event.new(:foo, :payload => :bar)
event = event(:foo, :payload => :bar)
assert_equal :foo, event.name
assert_equal Hash[:payload => :bar], event.payload
end
def test_events_consumes_information_given_as_payload
event = ActiveSupport::Orchestra::Event.new(:foo,
:time => (time = Time.now), :result => 1, :duration => 10)
event = event(:foo, :time => (time = Time.now), :result => 1, :duration => 10)
assert_equal Hash.new, event.payload
assert_equal time, event.time
assert_equal 1, event.result
assert_equal 10, event.duration
end
def test_event_is_parent_based_on_time_frame
parent = event(:foo, :time => Time.utc(2009), :duration => 10000)
child = event(:foo, :time => Time.utc(2009, 01, 01, 0, 0, 1), :duration => 1000)
not_child = event(:foo, :time => Time.utc(2009, 01, 01, 0, 0, 1), :duration => 10000)
assert parent.parent_of?(child)
assert !child.parent_of?(parent)
assert !parent.parent_of?(not_child)
assert !not_child.parent_of?(parent)
end
protected
def event(*args)
ActiveSupport::Orchestra::Event.new(*args)
end
end
class OrchestraMainTest < Test::Unit::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册