Skip to content

Commit

Permalink
Make time based tests less likely to fail non-deterministically
Browse files Browse the repository at this point in the history
These tests deal with real durations of time, and can fail due to GC or
other performance impacting events.  Increase the time scales slightly
to make them less prone for sporadic failure.
  • Loading branch information
Sam Goldstein committed May 18, 2012
1 parent 7cddc6c commit 0b3cd36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions test/new_relic/agent/transaction_sampler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,17 @@ def test_harvest_slowest
slowest = @sampler.harvest(nil, 0)[0]
assert((slowest.duration >= 0.09), "expected sample duration >= 0.09, but was: #{slowest.duration.inspect}")
# this assert is here to make sure the test remains valid
assert((slowest.duration <= 0.15), "expected sample duration <= 0.15, but was: #{slowest.duration.inspect}")
assert((slowest.duration <= 0.2), "expected sample duration <= 0.15, but was: #{slowest.duration.inspect}")


run_sample_trace { sleep 0.0001 }
not_as_slow = @sampler.harvest(slowest, 0)[0]
assert((not_as_slow == slowest), "Should re-harvest the same transaction since it should be slower than the new transaction - expected #{slowest.inspect} but got #{not_as_slow.inspect}")

run_sample_trace { sleep 0.16 }
run_sample_trace { sleep 0.25 }
new_slowest = @sampler.harvest(slowest, 0)[0]
assert((new_slowest != slowest), "Should not harvest the same trace since the new one should be slower")
assert((new_slowest.duration >= 0.15), "Slowest duration must be >= 0.15, but was: #{new_slowest.duration.inspect}")
assert((new_slowest.duration >= 0.2), "Slowest duration must be >= 0.15, but was: #{new_slowest.duration.inspect}")
end

def test_prepare_to_send
Expand Down
4 changes: 2 additions & 2 deletions test/new_relic/agent/worker_loop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def test_density
# This shows how the tasks stay aligned with the period and don't drift.
count = 0
start = Time.now
@worker_loop.run(0.01) do
@worker_loop.run(0.03) do
count +=1
if count == 3
@worker_loop.stop
next
end
end
elapsed = Time.now - start
assert_in_delta 0.03, elapsed, 0.02
assert_in_delta 0.09, elapsed, 0.02
end
def test_task_error__standard
@logger.expects(:debug)
Expand Down

0 comments on commit 0b3cd36

Please sign in to comment.