raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / Atom feed
15df0875f3686d133cbec2411b8a0102e61634d7 blob 2252 bytes (raw)

 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
74
75
76
77
78
79
80
81
82
83
84
85
 
# -*- encoding: binary -*-
require 'test/unit'
require 'tempfile'
require 'raindrops'
require 'socket'
require 'pp'
$stderr.sync = $stdout.sync = true
class TestTCP_Info < Test::Unit::TestCase

  TEST_ADDR = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'

  # Linux kernel commit 5ee3afba88f5a79d0bff07ddd87af45919259f91
  TCP_INFO_useful_listenq = `uname -r`.strip >= '2.6.24'

  def test_tcp_server_unacked
    return if RUBY_PLATFORM !~ /linux/ # unacked not implemented on others...
    s = TCPServer.new(TEST_ADDR, 0)
    rv = Raindrops::TCP_Info.new s
    c = TCPSocket.new TEST_ADDR, s.addr[1]
    tmp = Raindrops::TCP_Info.new s
    TCP_INFO_useful_listenq and assert_equal 1, tmp.unacked

    assert_equal 0, rv.unacked
    a = s.accept
    tmp = Raindrops::TCP_Info.new s
    assert_equal 0, tmp.unacked
    before = tmp.object_id

    tmp.get!(s)
    assert_equal before, tmp.object_id

  ensure
    [ c, a, s ].compact.each(&:close)
  end

  def test_accessors
    s = TCPServer.new TEST_ADDR, 0
    tmp = Raindrops::TCP_Info.new s
    tcp_info_methods = tmp.methods - Object.new.methods
    assert tcp_info_methods.size >= 32
    tcp_info_methods.each do |m|
      next if m.to_sym == :get!
      next if ! tmp.respond_to?(m)
      val = tmp.__send__ m
      assert_kind_of Integer, val
      assert val >= 0
    end
    assert tmp.respond_to?(:state), 'every OS knows about TCP state, right?'
  ensure
    s.close
  end

  def test_tcp_server_delayed
    delay = 0.010
    delay_ms = (delay * 1000).to_i
    s = TCPServer.new(TEST_ADDR, 0)
    c = TCPSocket.new TEST_ADDR, s.addr[1]
    c.syswrite "."
    sleep(delay * 1.2)
    a = s.accept
    i = Raindrops::TCP_Info.new(a)
    assert i.last_data_recv >= delay_ms, "#{i.last_data_recv} < #{delay_ms}"
    ensure
      c.close if c
      a.close if a
      s.close
  end

  def test_tcp_server_state_closed
    s = TCPServer.new(TEST_ADDR, 0)
    c = TCPSocket.new(TEST_ADDR, s.addr[1])
    i = Raindrops::TCP_Info.allocate
    a = s.accept
    i.get!(a)
    state = i.state
    c = c.close
    sleep(0.01) # wait for kernel to update state
    i.get!(a)
    assert_not_equal state, i.state
  ensure
    s.close if s
    c.close if c
    a.close if a
  end
end if defined? Raindrops::TCP_Info
debug log:

solving 15df087 ...
found 15df087 in https://bogomips.org/raindrops.git

raindrops RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/raindrops-public
	git clone --mirror http://ou63pmih66umazou.onion/raindrops-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.raindrops
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.raindrops

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox