diff options
| author | Yusuke Endoh <mame@ruby-lang.org> | 2024-06-24 12:28:03 +0900 |
|---|---|---|
| committer | Yusuke Endoh <mame@ruby-lang.org> | 2024-06-24 13:18:21 +0900 |
| commit | 96b45e61ca4ae99b9a52561db37d3cec229f1695 (patch) | |
| tree | 38db10200373344d3f8007c94850564a7c3757be /test/ruby | |
| parent | ace17ba3cd603de017bb894509bb2e60af1d1b9f (diff) | |
Introduce retry to the setup of test files with TestFile#test_stat
GitHub Actions macos-arm-oss is often too slow and does not timestamp as
expected.
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_file.rb | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index b7cd89d32f..6164e5b9e5 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -365,26 +365,38 @@ class TestFile < Test::Unit::TestCase file.close path = file.path - t0 = Process.clock_gettime(Process::CLOCK_REALTIME) - File.write(path, "foo") - sleep 2 - File.write(path, "bar") - sleep 2 - File.read(path) - File.chmod(0644, path) - sleep 2 - File.read(path) - - delta = EnvUtil.apply_timeout_scale(1) + retry_count = 0 + while true + t0 = Process.clock_gettime(Process::CLOCK_REALTIME) + File.write(path, "foo") + sleep 2 + t1 = Process.clock_gettime(Process::CLOCK_REALTIME) + File.write(path, "bar") + sleep 2 + t2 = Process.clock_gettime(Process::CLOCK_REALTIME) + File.read(path) + File.chmod(0644, path) + sleep 2 + t3 = Process.clock_gettime(Process::CLOCK_REALTIME) + File.read(path) + + t4 = Process.clock_gettime(Process::CLOCK_REALTIME) + break if t4 - t0 < 6.5 + + retry_count += 1 + raise "failed to setup; the machine is too slow? #{t0} #{t1} #{t2} #{t3} #{t4}" if retry_count > 3 + end + + delta = 1 stat = File.stat(path) - assert_in_delta tb, stat.birthtime.to_f, delta - assert_in_delta t0+2, stat.mtime.to_f, delta + assert_in_delta tb, stat.birthtime.to_f, delta + assert_in_delta t1, stat.mtime.to_f, delta if stat.birthtime != stat.ctime - assert_in_delta t0+4, stat.ctime.to_f, delta + assert_in_delta t2, stat.ctime.to_f, delta end if /mswin|mingw/ !~ RUBY_PLATFORM && !Bug::File::Fs.noatime?(path) # Windows delays updating atime - assert_in_delta t0+6, stat.atime.to_f, delta + assert_in_delta t3, stat.atime.to_f, delta end } rescue NotImplementedError |
