зеркало из https://github.com/github/dat-science.git
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:
Родитель
eeb4b163d0
Коммит
cff2c6cd78
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче