Skip to content

Commit d8f6280

Browse files
committed
Loosen time assertions
The time it takes to come back from sleep can be quite variable, but we can guarantee that it is _at least_ that long. I loosened this from a 0.5 millisecond buffer to a 10 millisecond buffer, it's possible that isn't even enough on some platforms. I also shortened the sleep duration from 100ms each to 10ms, to make our test suite faster.
1 parent 7abc8fb commit d8f6280

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

activesupport/test/benchmark_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
class BenchmarkTest < ActiveSupport::TestCase
66
def test_realtime
7-
time = ActiveSupport::Benchmark.realtime { sleep 0.1 }
8-
assert_in_delta 0.1, time, 0.0005
7+
time = ActiveSupport::Benchmark.realtime { sleep 0.01 }
8+
assert_includes (0.01..0.02), time
99
end
1010

1111
def test_realtime_millisecond
12-
ms = ActiveSupport::Benchmark.realtime(:float_millisecond) { sleep 0.1 }
13-
assert_in_delta 100, ms, 0.5
12+
ms = ActiveSupport::Benchmark.realtime(:float_millisecond) { sleep 0.01 }
13+
assert_includes (10..20), ms
1414
end
1515
end

activesupport/test/core_ext/benchmark_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class BenchmarkTest < ActiveSupport::TestCase
77
def test_is_deprecated
88
assert_deprecated(ActiveSupport.deprecator) do
9-
assert_operator Benchmark.ms { }, :>, 0
9+
assert_kind_of Numeric, Benchmark.ms { }
1010
end
1111
end
1212
end

0 commit comments

Comments
 (0)