diff options
Diffstat (limited to 'test/ruby/test_file.rb')
| -rw-r--r-- | test/ruby/test_file.rb | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 6164e5b9e5..a3d6221c0f 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -358,45 +358,58 @@ class TestFile < Test::Unit::TestCase assert_equal(mod_time_contents, stats.mtime, bug6385) end + def measure_time + log = [] + 30.times do + t1 = Process.clock_gettime(Process::CLOCK_REALTIME) + yield + t2 = Process.clock_gettime(Process::CLOCK_REALTIME) + log << (t2 - t1) + return (t1 + t2) / 2 if t2 - t1 < 1 + sleep 1 + end + omit "failed to setup; the machine is stupidly slow #{log.inspect}" + end + def test_stat - tb = Process.clock_gettime(Process::CLOCK_REALTIME) + btime = Process.clock_gettime(Process::CLOCK_REALTIME) Tempfile.create("stat") {|file| - tb = (tb + Process.clock_gettime(Process::CLOCK_REALTIME)) / 2 + btime = (btime + Process.clock_gettime(Process::CLOCK_REALTIME)) / 2 file.close path = file.path - retry_count = 0 - while true - t0 = Process.clock_gettime(Process::CLOCK_REALTIME) + measure_time do File.write(path, "foo") - sleep 2 - t1 = Process.clock_gettime(Process::CLOCK_REALTIME) + end + + sleep 2 + + mtime = measure_time do File.write(path, "bar") - sleep 2 - t2 = Process.clock_gettime(Process::CLOCK_REALTIME) - File.read(path) + end + + sleep 2 + + ctime = measure_time do File.chmod(0644, path) - sleep 2 - t3 = Process.clock_gettime(Process::CLOCK_REALTIME) - File.read(path) + end - t4 = Process.clock_gettime(Process::CLOCK_REALTIME) - break if t4 - t0 < 6.5 + sleep 2 - retry_count += 1 - raise "failed to setup; the machine is too slow? #{t0} #{t1} #{t2} #{t3} #{t4}" if retry_count > 3 + atime = measure_time do + File.read(path) end delta = 1 stat = File.stat(path) - assert_in_delta tb, stat.birthtime.to_f, delta - assert_in_delta t1, stat.mtime.to_f, delta + assert_in_delta btime, stat.birthtime.to_f, delta + assert_in_delta mtime, stat.mtime.to_f, delta if stat.birthtime != stat.ctime - assert_in_delta t2, stat.ctime.to_f, delta + assert_in_delta ctime, stat.ctime.to_f, delta end if /mswin|mingw/ !~ RUBY_PLATFORM && !Bug::File::Fs.noatime?(path) # Windows delays updating atime - assert_in_delta t3, stat.atime.to_f, delta + assert_in_delta atime, stat.atime.to_f, delta end } rescue NotImplementedError |
