Skip to content

Commit

Permalink
try and stabilize unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed Feb 3, 2013
1 parent 32dca7f commit 2926634
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/copy_data_to_server.rb
Expand Up @@ -348,7 +348,12 @@ def wait_for_all_clients_to_copy_files_out
end
sleep! :server, "detected all clients are done, deleting their notification files", 0
for file in client_done_copying_files
File.delete file
begin
File.delete file
rescue Errno::EACCES => file_being_touched_right_now # mostly for unit tests...
p 'retrying delete ' + file
retry
end
p 'deletec', file, File.exist?(file)
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/copy_from_server.rb
Expand Up @@ -51,14 +51,14 @@ def copy_files_from_dropbox_to_local_permanent_storage size_expected

def recombinate_files_split_piece_wise filenames
regex = /^(.+)___piece_(\d+)_of_(\d+)_total_size_(\d+)_md5_(.*)$/
filenames = filenames.select{|f| f =~ regex}.sort_by{|f| f =~ regex; [$1, Integer($2)]}
filenames_to_recombo = filenames.select{|f| f =~ regex}.sort_by{|f| f =~ regex; [$1, Integer($2)]}
previous_number = nil
previous_name = nil
previous_total_size = nil
previous_md5 = nil
current_handle = nil
current_total_pieces_number = nil
for filename in filenames
for filename in filenames_to_recombo
sleep!(:client, "recombinating file #{filename}", 0)
filename =~ regex
incoming_filename = $1
Expand Down Expand Up @@ -119,10 +119,10 @@ def recombinate_files_split_piece_wise filenames
end
end

assert current_handle == nil # should have been closed...
filenames.each{|f| File.delete f} # don't want the old partial files anymore...
assert current_handle == nil # should have been already closed...
filenames_to_recombo.each{|f| File.delete f} # don't want the old partial files anymore...
ensure
current_handle.close if current_handle
current_handle.close if current_handle # error condition
end

attr_accessor :extra_stuff_for_done_file # for multiple instances, in unit tests, to be able to differentiate themselves in stop file name
Expand Down

0 comments on commit 2926634

Please sign in to comment.