Skip to content

Commit

Permalink
Fixed slow tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Mar 12, 2011
1 parent 471e3b9 commit 1c6e4db
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/filecreation.rb
Expand Up @@ -5,13 +5,16 @@ module FileCreation
NEWFILE = "testdata/new"

def create_timed_files(oldfile, *newfiles)
return if File.exist?(oldfile) && newfiles.all? { |newfile| File.exist?(newfile) }
old_time = create_file(oldfile)
return if (File.exist?(oldfile) &&
newfiles.all? { |newfile|
File.exist?(newfile) && File.stat(newfile).mtime > File.stat(oldfile).mtime
})
now = Time.now

create_file(oldfile, now - 60)

newfiles.each do |newfile|
while create_file(newfile) <= old_time
sleep(0.1)
File.delete(newfile) rescue nil
end
create_file(newfile, now)
end
end

Expand All @@ -20,9 +23,10 @@ def create_dir(dirname)
File.stat(dirname).mtime
end

def create_file(name)
def create_file(name, file_time=nil)
create_dir(File.dirname(name))
FileUtils.touch(name) unless File.exist?(name)
File.utime(file_time, file_time, name) unless file_time.nil?
File.stat(name).mtime
end

Expand Down

0 comments on commit 1c6e4db

Please sign in to comment.