Sha256: 28084f98cc43703ff48ed42cec8de8bc2c7972b1c6c66f75985e2eb378273f4b

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

#!/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 }

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
net_dav-0.5.1 script/multi-test
net_dav-0.5.0 script/multi-test
net_dav-0.4.1 script/multi-test
net_dav-0.4.0 script/multi-test
net_dav-0.3.3 script/multi-test
net_dav-0.3.2 script/multi-test
net_dav-0.3.1 script/multi-test
net_dav-0.3.0 script/multi-test
net_dav-0.2.2 script/multi-test