Put exceptions on the wire as a hash

This should address issues we were seeing with published exceptions
not having any real data.
This commit is contained in:
Rick Bradley 2013-08-30 23:45:38 +02:00
Родитель eeb4b163d0
Коммит cff2c6cd78
2 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -37,11 +37,16 @@ module Dat
def payload
{
:duration => duration,
:exception => exception,
:exception => serialize_exception(exception),
:value => experiment.clean(value)
}
end
def serialize_exception(exception)
return nil unless exception
{ :class => exception.class.name, :message => exception.message }
end
def raised?
!!exception
end

Просмотреть файл

@ -257,4 +257,22 @@ class DatScienceExperimentTest < MiniTest::Unit::TestCase
refute_nil payload[:control][:exception]
refute_nil payload[:candidate][:exception]
end
def test_publishes_exception_data
e = Experiment.new "foo"
e.control { raise "foo" }
e.candidate { raise "bar" }
assert_raises RuntimeError do
e.run
end
event, payload = Experiment.published.first
refute_nil event
refute_nil payload
assert_equal :mismatch, event
assert_equal({ :message => 'foo', :class => 'RuntimeError' }, payload[:control][:exception])
assert_equal({ :message => 'bar', :class => 'RuntimeError' }, payload[:candidate][:exception])
end
end