Last active
August 29, 2015 14:03
-
-
Save qwertme/ec455e0a543db669c0ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tempfile' | |
class WriteAndReadRunner | |
class FileNotFoundError < StandardError; end | |
def initialize(count = 200) | |
@all_files = [] | |
@count = count | |
end | |
def run | |
@count.times.each do |count_index| | |
@all_files << write_new_file | |
if !find_file?(@all_files.last.path) | |
raise FileNotFoundError, "File #{@all_files.last} not found at count_index: #{count_index}" | |
end | |
end | |
cleanup_files | |
puts "Completed #{@count} run(s) without error" | |
end | |
private | |
def cleanup_files | |
@all_files.each_with_index do |file, file_index| | |
begin | |
file.unlink | |
rescue Errno::ENOENT | |
puts "Error deleting file index #{file_index}" | |
raise | |
end | |
end | |
end | |
def write_new_file | |
file = Tempfile.new(['meta', '.in-progress']) | |
IO.write(file.path, 'foo') | |
file.close | |
file | |
end | |
def find_file?(path) | |
File.file?(path) | |
end | |
end | |
if $0 == __FILE__ | |
count = ARGV[0].to_i | |
WriteAndReadRunner.new(count).run | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment