File: test_connection.rb

package info (click to toggle)
ruby1.8 1.8.7.302-2squeeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 26,640 kB
  • ctags: 38,616
  • sloc: ruby: 245,002; ansic: 144,156; yacc: 5,890; sh: 2,677; lisp: 1,626; tcl: 949; makefile: 358; sed: 129; xml: 122; awk: 36; cpp: 28; asm: 25; perl: 18; python: 6
file content (33 lines) | stat: -rw-r--r-- 782 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
require 'net/http'
require 'test/unit'

module TestHTTP
  class HTTPConnectionTest < Test::Unit::TestCase
    def test_connection_refused_in_request
      bug2708 = '[ruby-core:28028]'
      port = nil
      localhost = "127.0.0.1"
      t = Thread.new {
        TCPServer.open(localhost, 0) do |serv|
          _, port, _, _ = serv.addr
          if clt = serv.accept
            clt.close
          end
        end
      }
      begin
        sleep 0.1 until port
        assert_raise(EOFError, bug2708) {
          n = Net::HTTP.new(localhost, port)
          n.request_get('/')
        }
      ensure
        t.join if t
      end
      assert_raise(Errno::ECONNREFUSED, bug2708) {
        n = Net::HTTP.new(localhost, port)
        n.request_get('/')
      }
    end
  end
end