curb 0.5.8.0-x86-linux → 0.7.7-x86-linux

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curb might be problematic. Click here for more details.

@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+ #require 'rubygems'
3
+ #require 'rmem'
4
+
5
+ #
6
+ # Run some tests to measure the memory usage of curb, these tests require fork and ps
7
+ #
8
+ class TestCurbMemory < Test::Unit::TestCase
9
+
10
+ def test_easy_memory
11
+ easy_avg, easy_std = measure_object_memory(Curl::Easy)
12
+ printf "Easy average: %.2f kilobytes +/- %.2f kilobytes\n", easy_avg.to_f, easy_std.to_f
13
+
14
+ multi_avg, multi_std = measure_object_memory(Curl::Multi)
15
+ printf "Multi average: %.2f kilobytes +/- %.2f kilobytes\n", multi_avg.to_f, multi_std.to_f
16
+
17
+ # now that we have the average size of an easy handle lets see how much a multi request consumes with 10 requests
18
+ end
19
+
20
+ def c_avg(report)
21
+ sum = 0
22
+ report.each {|r| sum += r.last }
23
+ (sum.to_f / report.size)
24
+ end
25
+
26
+ def c_std(report,avg)
27
+ var = 0
28
+ report.each {|r| var += (r.last-avg)*(r.last-avg) }
29
+ Math.sqrt(var / (report.size-1))
30
+ end
31
+
32
+ def measure_object_memory(klass)
33
+ report = []
34
+ 200.times do
35
+ res = mem_check do
36
+ obj = klass.new
37
+ end
38
+ report << res
39
+ end
40
+ avg = c_avg(report)
41
+ std = c_std(report,avg)
42
+ [avg,std]
43
+ end
44
+
45
+ def mem_check
46
+ # see: http://gist.github.com/264060 for inspiration of ps command line
47
+ rd, wr = IO.pipe
48
+ memory_usage = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
49
+ fork do
50
+ before = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
51
+ rd.close
52
+ yield
53
+ after = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
54
+ wr.write((after - before))
55
+ wr.flush
56
+ wr.close
57
+ end
58
+ wr.close
59
+ total = rd.read.to_i
60
+ rd.close
61
+ Process.wait
62
+ # return the delta and the total
63
+ [memory_usage, total]
64
+ end
65
+ end
@@ -57,8 +57,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
57
57
  assert_equal nil, c.on_body
58
58
  end
59
59
 
60
- class Foo < Curl::Easy
61
- end
60
+ class Foo < Curl::Easy ; end
62
61
  def test_new_05
63
62
  # can use Curl::Easy as a base class
64
63
  c = Foo.new
@@ -554,6 +553,12 @@ class TestCurbCurlEasy < Test::Unit::TestCase
554
553
  assert_equal 'DELETE', curl.body_str
555
554
  end
556
555
 
556
+ def test_arbitrary_http_verb
557
+ curl = Curl::Easy.new(TestServlet.url)
558
+ curl.http('PURGE')
559
+ assert_equal 'PURGE', curl.body_str
560
+ end
561
+
557
562
  def test_head_remote
558
563
  curl = Curl::Easy.new(TestServlet.url)
559
564
  curl.http_head
@@ -655,6 +660,115 @@ class TestCurbCurlEasy < Test::Unit::TestCase
655
660
  assert /ScrubDog$/,curl.useragent
656
661
  end
657
662
 
663
+ def test_username_password
664
+ curl = Curl::Easy.new(TestServlet.url)
665
+ curl.username = "foo"
666
+ curl.password = "bar"
667
+ if !curl.username.nil?
668
+ assert_equal "foo", curl.username
669
+ assert_equal "bar", curl.password
670
+ else
671
+ curl.userpwd = "foo:bar"
672
+ end
673
+ curl.http_auth_types = :basic
674
+ #curl.verbose = true
675
+ curl.perform
676
+ assert_equal 'Basic Zm9vOmJhcg==', $auth_header
677
+ $auth_header = nil
678
+ # curl checks the auth type supported by the server, so we have to create a
679
+ # new easy handle if we're going to change the auth type...
680
+
681
+ curl = Curl::Easy.new(TestServlet.url)
682
+ curl.username = "foo"
683
+ curl.password = "bar"
684
+ if curl.username.nil?
685
+ curl.userpwd = "foo:bar"
686
+ end
687
+ curl.http_auth_types = :ntlm
688
+ curl.perform
689
+ assert_equal 'NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=', $auth_header
690
+ end
691
+
692
+ def test_primary_ip
693
+ curl = Curl::Easy.new(TestServlet.url)
694
+ if curl.respond_to?(:primary_ip)
695
+ curl.perform
696
+ assert_equal '127.0.0.1', curl.primary_ip
697
+ end
698
+ end
699
+
700
+ def test_post_streaming
701
+ readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README'))
702
+
703
+ pf = Curl::PostField.file("filename", readme)
704
+
705
+ easy = Curl::Easy.new
706
+
707
+ easy.url = TestServlet.url
708
+ easy.multipart_form_post = true
709
+ easy.http_post(pf)
710
+
711
+ assert_not_equal(0,easy.body_str.size)
712
+ assert_equal(easy.body_str,File.read(readme))
713
+ end
714
+
715
+
716
+ def test_easy_close
717
+ easy = Curl::Easy.new
718
+ easy.close
719
+ easy.url = TestServlet.url
720
+ easy.http_get
721
+ end
722
+
723
+ def test_easy_reset
724
+ easy = Curl::Easy.new
725
+ easy.url = TestServlet.url + "?query=foo"
726
+ easy.http_get
727
+ settings = easy.reset
728
+ assert settings.key?(:url)
729
+ assert settings.key?(:body_data)
730
+ assert settings.key?(:header_data)
731
+ easy.url = TestServlet.url
732
+ easy.http_get
733
+ end
734
+
735
+ def test_easy_use_http_versions
736
+ easy = Curl::Easy.new
737
+ easy.url = TestServlet.url + "?query=foo"
738
+ #puts "http none: #{Curl::HTTP_NONE.inspect}"
739
+ #puts "http1.0: #{Curl::HTTP_1_0.inspect}"
740
+ #puts "http1.1: #{Curl::HTTP_1_1.inspect}"
741
+ easy.version = Curl::HTTP_1_1
742
+ #easy.verbose = true
743
+ easy.http_get
744
+ end
745
+
746
+ def test_easy_http_verbs
747
+ curl = Curl::Easy.new(TestServlet.url)
748
+ curl.http_delete
749
+ assert_equal 'DELETE', curl.body_str
750
+ curl.http_get
751
+ assert_equal 'GET', curl.body_str
752
+ curl.http_post
753
+ assert_equal "POST\n", curl.body_str
754
+ curl.http('PURGE')
755
+ assert_equal 'PURGE', curl.body_str
756
+ curl.http_put('hello')
757
+ assert_equal "PUT\nhello", curl.body_str
758
+ end
759
+
760
+ # http://github.com/taf2/curb/issues/#issue/33
761
+ def test_easy_http_verbs_with_errors
762
+ curl = Curl::Easy.new("http://127.0.0.1:9012/") # test will fail if http server on port 9012
763
+ assert_raise Curl::Err::ConnectionFailedError do
764
+ curl.http_delete
765
+ end
766
+ curl.url = TestServlet.url
767
+ curl.http_get
768
+ assert_equal 'GET', curl.body_str
769
+ end
770
+
771
+
658
772
  include TestServerMethods
659
773
 
660
774
  def setup
@@ -44,7 +44,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
44
44
 
45
45
  m.perform do
46
46
  # idle
47
- puts "idling..."
47
+ #puts "idling..."
48
48
  end
49
49
 
50
50
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c1.body_str)
@@ -170,7 +170,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
170
170
 
171
171
  m.perform do
172
172
  # idle
173
- puts "idling..."
173
+ #puts "idling..."
174
174
  end
175
175
 
176
176
  assert success_called2
@@ -308,6 +308,27 @@ class TestCurbCurlMulti < Test::Unit::TestCase
308
308
  end
309
309
  end
310
310
 
311
+ def test_multi_easy_download_01
312
+ # test collecting response buffers to file e.g. on_body
313
+ root_uri = 'http://127.0.0.1:9129/ext/'
314
+ urls = []
315
+ downloads = []
316
+ file_info = {}
317
+ FileUtils.mkdir("tmp/")
318
+ Dir[File.dirname(__FILE__) + "/../ext/*.c"].each do|path|
319
+ urls << (root_uri + File.basename(path))
320
+ downloads << "tmp/" + File.basename(path)
321
+ file_info[File.basename(path)] = {:size => File.size(path)}
322
+ end
323
+ Curl::Multi.download(urls,{},{},downloads) do|curl,download_path|
324
+ assert_equal 200, curl.response_code
325
+ assert File.exist?(download_path)
326
+ assert file_info[File.basename(download_path)][:size], File.size(download_path)
327
+ end
328
+ ensure
329
+ FileUtils.rm_rf("tmp/")
330
+ end
331
+
311
332
  def test_multi_easy_post_01
312
333
  urls = [
313
334
  { :url => TestServlet.url + '?q=1', :post_fields => {'field1' => 'value1', 'k' => 'j'}},
@@ -381,7 +402,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
381
402
 
382
403
  def test_remove_exception_is_descriptive
383
404
  m = Curl::Multi.new
384
- c = Curl::Easy.new("http://blah.com")
405
+ c = Curl::Easy.new("http://127.9.9.9:999110")
385
406
  m.remove(c)
386
407
  rescue => e
387
408
  assert_equal 'Invalid easy handle', e.message
@@ -391,11 +412,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
391
412
  def test_retry_easy_handle
392
413
  m = Curl::Multi.new
393
414
 
394
- tries = 2
415
+ tries = 10
395
416
 
396
- c1 = Curl::Easy.new('http://127.9.9.9') do |curl|
417
+ c1 = Curl::Easy.new('http://127.1.1.1:99911') do |curl|
397
418
  curl.on_failure {|c,e|
398
- assert_equal [Curl::Err::ConnectionFailedError, "Couldn't connect to server"], e
419
+ assert_equal [Curl::Err::MalformedURLError, "URL using bad/illegal format or missing URL"], e
399
420
  if tries > 0
400
421
  tries -= 1
401
422
  m.add(c)
@@ -406,10 +427,29 @@ class TestCurbCurlMulti < Test::Unit::TestCase
406
427
  tries -= 1
407
428
  m.add(c1)
408
429
 
409
- while not m.requests.empty?
410
- m.perform
411
- end
430
+ m.perform
412
431
  assert_equal 0, tries
432
+ assert_equal 0, m.requests.size
433
+ end
434
+
435
+ def test_reusing_handle
436
+ m = Curl::Multi.new
437
+
438
+ c = Curl::Easy.new('http://127.0.0.1') do|easy|
439
+ easy.on_complete{|e,r| puts e.inspect }
440
+ end
441
+
442
+ m.add(c)
443
+ m.add(c)
444
+ rescue => e
445
+ assert_equal Curl::Err::MultiBadEasyHandle, e.class
446
+ end
447
+
448
+ def test_multi_default_timeout
449
+ assert_equal 100, Curl::Multi.default_timeout
450
+ Curl::Multi.default_timeout = 12
451
+ assert_equal 12, Curl::Multi.default_timeout
452
+ assert_equal 100, (Curl::Multi.default_timeout = 100)
413
453
  end
414
454
 
415
455
  include TestServerMethods
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8.0
4
+ hash: 13
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 7
10
+ version: 0.7.7
5
11
  platform: x86-linux
6
12
  authors:
7
13
  - Ross Bamford
@@ -10,7 +16,7 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2009-11-23 00:00:00 -05:00
19
+ date: 2010-06-21 00:00:00 -04:00
14
20
  default_executable:
15
21
  dependencies: []
16
22
 
@@ -51,6 +57,23 @@ files:
51
57
  - ext/curb_multi.o
52
58
  - ext/curb.o
53
59
  - ext/curb_core.so
60
+ - tests/bugtests.rb
61
+ - tests/mem_check.rb
62
+ - tests/bug_require_last_or_segfault.rb
63
+ - tests/helper.rb
64
+ - tests/tc_curl_postfield.rb
65
+ - tests/bug_instance_post_differs_from_class_post.rb
66
+ - tests/bug_multi_segfault.rb
67
+ - tests/alltests.rb
68
+ - tests/bug_postfields_crash.rb
69
+ - tests/require_last_or_segfault_script.rb
70
+ - tests/bug_postfields_crash2.rb
71
+ - tests/unittests.rb
72
+ - tests/tc_curl_multi.rb
73
+ - tests/bug_curb_easy_post_with_string_no_content_length_header.rb
74
+ - tests/tc_curl_download.rb
75
+ - tests/tc_curl_easy.rb
76
+ - tests/bug_curb_easy_blocks_ruby_threads.rb
54
77
  has_rdoc: true
55
78
  homepage: http://curb.rubyforge.org/
56
79
  licenses: []
@@ -63,34 +86,45 @@ require_paths:
63
86
  - lib
64
87
  - ext
65
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
66
90
  requirements:
67
91
  - - ">="
68
92
  - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
69
96
  version: "0"
70
- version:
71
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
72
99
  requirements:
73
100
  - - ">="
74
101
  - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
75
105
  version: "0"
76
- version:
77
106
  requirements: []
78
107
 
79
108
  rubyforge_project: curb
80
- rubygems_version: 1.3.5
109
+ rubygems_version: 1.3.7
81
110
  signing_key:
82
111
  specification_version: 3
83
112
  summary: Ruby libcurl bindings
84
113
  test_files:
114
+ - tests/bugtests.rb
115
+ - tests/mem_check.rb
85
116
  - tests/bug_require_last_or_segfault.rb
86
117
  - tests/helper.rb
87
118
  - tests/tc_curl_postfield.rb
88
119
  - tests/bug_instance_post_differs_from_class_post.rb
89
120
  - tests/bug_multi_segfault.rb
90
121
  - tests/alltests.rb
122
+ - tests/bug_postfields_crash.rb
91
123
  - tests/require_last_or_segfault_script.rb
124
+ - tests/bug_postfields_crash2.rb
92
125
  - tests/unittests.rb
93
126
  - tests/tc_curl_multi.rb
127
+ - tests/bug_curb_easy_post_with_string_no_content_length_header.rb
94
128
  - tests/tc_curl_download.rb
95
129
  - tests/tc_curl_easy.rb
96
130
  - tests/bug_curb_easy_blocks_ruby_threads.rb