#!/usr/bin/env ruby require 'zlib' require 'uri' require 'rubygems' require 'net/dav' url = URI.parse $*[0] items = [] reps = 10 nthreads = 10 use_curl = true use_curl = false if ENV['DISABLE_CURL'] Net::DAV.start(url, :curl => use_curl) do |dav| dav.find(url.path) do |item| items << item end end curindex = 0 nitems = items.size / nthreads + 1 nitems = 1 if nitems < 1 threads = [] (1..nthreads).each do |tind| next if curindex >= items.size titems = items[curindex, nitems] curindex += nitems threads << Thread.new(tind, titems) do |tind, titems| Net::DAV.start(url, :curl => use_curl) do |dav| Thread.current.abort_on_exception = true crcs = {} (1..reps).each do titems.each do |item| total_size = 0 crc = 0 dav.get(item.uri.path) do |str| #puts "get #{item.uri} #{total_size}" total_size += str.length crc = Zlib.crc32(str, crc) end puts "[#{tind}] new crc for #{item.uri}" if (crcs[item.uri].nil?) crcs[item.uri] = crc if (crcs[item.uri].nil?) raise "crc mismatch #{item} #{crc} #{crcs[item.uri]}" if (crc != crcs[item.uri]) raise "size mismatch #{item} #{item.size} #{total_size}" if (total_size != item.size) puts "[#{tind}] good #{item.uri} #{item.size} #{crc}" end end end end end threads.each { |thread| thread.join }