Allow a float error for Regexp.timeout

The tests failed on windows

https://github.com/ruby/ruby/actions/runs/3440997073/jobs/5740085169#step:18:62
```
    1) Failure:
  TestRegexp#test_s_timeout [D:/a/ruby/ruby/src/test/ruby/test_regexp.rb:1586]:
  <0.30000000000000004> expected but was
  <0.3>.

    2) Failure:
  TestRegexp#test_timeout_shorter_than_global [D:/a/ruby/ruby/src/test/ruby/test_regexp.rb:1631]:
  <0.30000000000000004> expected but was
  <0.3>.
```
This commit is contained in:
Yusuke Endoh 2022-11-11 09:05:51 +09:00
parent 4c554096bf
commit adfbee85e0

View File

@ -1583,7 +1583,7 @@ class TestRegexp < Test::Unit::TestCase
timeout = #{ EnvUtil.apply_timeout_scale(0.2).inspect }
begin;
Regexp.timeout = timeout
assert_equal(timeout, Regexp.timeout)
assert_in_delta(timeout, Regexp.timeout, timeout * 2 * Float::EPSILON)
t = Time.now
assert_raise_with_message(Regexp::TimeoutError, "regexp match timeout") do
@ -1628,7 +1628,11 @@ class TestRegexp < Test::Unit::TestCase
Regexp.timeout = global_timeout
re = Regexp.new("^(a*)\\1b?a*$", timeout: per_instance_timeout)
assert_equal(per_instance_timeout, re.timeout)
if per_instance_timeout
assert_in_delta(per_instance_timeout, re.timeout, per_instance_timeout * 2 * Float::EPSILON)
else
assert_nil(re.timeout)
end
t = Time.now
assert_raise_with_message(Regexp::TimeoutError, "regexp match timeout") do