From 3f4c37e92adaeef1ed7380f6afa013bceeeca5bc Mon Sep 17 00:00:00 2001 From: Rick Bradley Date: Tue, 26 Feb 2013 17:04:18 -0600 Subject: [PATCH 1/2] Add :timestamp to publish payload Now we can track when a particular result occurred. --- lib/dat/science/experiment.rb | 3 +++ test/dat_science_experiment_test.rb | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/dat/science/experiment.rb b/lib/dat/science/experiment.rb index 49e7d92..7424cb7 100644 --- a/lib/dat/science/experiment.rb +++ b/lib/dat/science/experiment.rb @@ -50,6 +50,8 @@ module Dat def run return run_control unless candidate? && enabled? + timestamp = Time.now + if control_runs_first? control = observe_control candidate = observe_candidate @@ -59,6 +61,7 @@ module Dat end payload = { + :timestamp => timestamp, :candidate => candidate.payload, :control => control.payload, :first => control_runs_first? ? :control : :candidate diff --git a/test/dat_science_experiment_test.rb b/test/dat_science_experiment_test.rb index d83d005..0e7625c 100644 --- a/test/dat_science_experiment_test.rb +++ b/test/dat_science_experiment_test.rb @@ -106,6 +106,8 @@ class DatScienceExperimentTest < MiniTest::Unit::TestCase assert_equal "foo", payload[:experiment] assert_equal :control, payload[:first] + assert (Time.now.to_i - payload[:timestamp].to_i) < 10 + assert payload[:control][:duration] assert_nil payload[:control][:exception] assert_equal :foo, payload[:control][:value] From 59700248c4ab97ec4fed5091c8ab101dd8c67d3e Mon Sep 17 00:00:00 2001 From: Rick Bradley Date: Tue, 26 Feb 2013 17:20:27 -0600 Subject: [PATCH 2/2] go with assert_in_delta to make :timestamp test palatable --- test/dat_science_experiment_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dat_science_experiment_test.rb b/test/dat_science_experiment_test.rb index 0e7625c..1ec97da 100644 --- a/test/dat_science_experiment_test.rb +++ b/test/dat_science_experiment_test.rb @@ -106,7 +106,7 @@ class DatScienceExperimentTest < MiniTest::Unit::TestCase assert_equal "foo", payload[:experiment] assert_equal :control, payload[:first] - assert (Time.now.to_i - payload[:timestamp].to_i) < 10 + assert_in_delta Time.now.to_f, payload[:timestamp].to_f, 2.0 assert payload[:control][:duration] assert_nil payload[:control][:exception]