File: bug_crash_on_progress.rb

package info (click to toggle)
ruby-curb 0.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 604 kB
  • ctags: 880
  • sloc: ansic: 4,242; ruby: 2,768; makefile: 3
file content (73 lines) | stat: -rw-r--r-- 1,726 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
require 'webrick'
class ::WEBrick::HTTPServer ; def access_log(config, req, res) ; end ; end
class ::WEBrick::BasicLog ; def log(level, data) ; end ; end

class BugCrashOnDebug < Test::Unit::TestCase
  
  def test_on_progress_raise
    server = WEBrick::HTTPServer.new( :Port => 9999 )
    server.mount_proc("/test") do|req,res|
      res.body = "hi"
      res['Content-Type'] = "text/html"
    end

    thread = Thread.new(server) do|srv|
      srv.start
    end

    c = Curl::Easy.new('http://127.0.0.1:9999/test')
    c.on_progress do|x|
      raise "error"
    end
    c.perform

    assert false, "should not reach this point"

  rescue => e
    assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
    c.close
  ensure
    server.shutdown
  end

  def test_on_progress_abort
    server = WEBrick::HTTPServer.new( :Port => 9999 )
    server.mount_proc("/test") do|req,res|
      res.body = "hi"
      res['Content-Type'] = "text/html"
    end

    thread = Thread.new(server) do|srv|
      srv.start
    end

    # see: https://github.com/taf2/curb/issues/192,
    # to pass:
    # 
    # c = Curl::Easy.new('http://127.0.0.1:9999/test')
    # c.on_progress do|x|
    #   puts "we're in the progress callback"
    #   false
    # end
    # c.perform
    # 
    #  notice no return keyword
    #
    c = Curl::Easy.new('http://127.0.0.1:9999/test')
    c.on_progress do|x|
      puts "we're in the progress callback"
      return false
    end
    c.perform

    assert false, "should not reach this point"

  rescue => e
    assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
    c.close
  ensure
    server.shutdown
  end

end