Project

General

Profile

Bug #4535 ยป 0002-test-socket-test_unix.rb-test-case-for-bug-4535.patch

test case which reproduces the fixed error on my machine - normalperson (Eric Wong), 03/29/2011 06:37 AM

View differences:

test/socket/test_unix.rb
6 6
require "test/unit"
7 7
require "tempfile"
8 8
require "tmpdir"
9
require "thread"
10
require "io/nonblock"
9 11

  
10 12
class TestSocket_UNIXSocket < Test::Unit::TestCase
11 13
  def test_fd_passing
......
102 104
    io_ary.each {|io| io.close if !io.closed? }
103 105
  end
104 106

  
107
  def test_fd_passing_race_condition
108
    r1, w = IO.pipe
109
    s1, s2 = UNIXSocket.pair
110
    s1.nonblock = s2.nonblock = true
111
    aoe = Thread.abort_on_exception
112
    Thread.abort_on_exception = true
113
    lock = Mutex.new
114
    nr = 0
115
    x = 2
116
    y = 1000
117
    begin
118
      s1.send_io(nil)
119
    rescue NotImplementedError
120
      assert_raise(NotImplementedError) { s2.recv_io }
121
    rescue TypeError
122
      thrs = x.times.map do
123
        Thread.new do
124
          y.times do
125
            s2.recv_io.close
126
            lock.synchronize { nr += 1 }
127
          end
128
        end
129
      end
130
      (x * y).times { s1.send_io r1 }
131
      thrs.each { |t| t.join }
132
      assert_equal x * y, nr
133
    ensure
134
      Thread.abort_on_exception = aoe
135
      s1.close
136
      s2.close
137
      w.close
138
      r1.close
139
    end
140
  end
141

  
105 142
  def test_sendmsg
106 143
    return if !defined?(Socket::SCM_RIGHTS)
107 144
    IO.pipe {|r1, w|
108
-