propfind_test.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. require 'test_helper'
  2. require 'ruby-prof'
  3. require 'benchmark'
  4. class PropfindTest < DAV4RackIntegrationTest
  5. def setup
  6. @handler = DAV4Rack::Handler.new
  7. @xml = render(:propfind) {|x| x.allprop }
  8. 1000.times do |index|
  9. FileUtils.mkdir_p(File.join(DOC_ROOT, "dir_#{index}"))
  10. end
  11. end
  12. def test_profile
  13. skip unless ENV['PROFILE']
  14. RubyProf.start
  15. propfind '/', input: @xml
  16. result = RubyProf.stop
  17. open("callgrind.html", "w") do |f|
  18. # RubyProf::GraphPrinter.new(result).print(f, {})
  19. # RubyProf::CallTreePrinter.new(result).print(f, :min_percent => 1)
  20. RubyProf::GraphHtmlPrinter.new(result).print(f, {})
  21. end
  22. end
  23. def test_propfind_should_be_fast
  24. # without ox 9.080960035324097
  25. # with ox 6.845001220703125
  26. # second pass with ox 4.0348320007
  27. b = Benchmark.measure do
  28. 10.times do
  29. propfind '/', input: @xml
  30. end
  31. end
  32. assert b.real <= 3.0, "time taken should be less than 3 seconds, was: #{b.real}"
  33. assert_match(/http:\/\/localhost(:\d+)?\//, multistatus_response('/d:href').first.text.strip)
  34. props = %w(creationdate displayname getlastmodified getetag resourcetype getcontenttype getcontentlength)
  35. props.each do |prop|
  36. refute multistatus_response("/d:propstat/d:prop/d:#{prop}").empty?
  37. end
  38. end
  39. end