summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-03 12:24:07 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-03 12:24:07 +0000
commit877a9a7d994fc9255db33f86d73f08870be8b234 (patch)
treedc02fcffbf0052ebb43282c048b2ac6ed9afd445 /test
parent8a571111295f8ce1720e10fd2760197951d481c7 (diff)
merges r32062 from trunk into ruby_1_9_2.
-- * ext/socket/unixsocket.c (unix_send_io): race condition fixed. (unix_recv_io): ditto. fixed by Eric Wong. [ruby-core:35574] * test/socket/test_unix.rb: test added for above problem. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@32383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/socket/test_unix.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb
index bde17cf0ab..d5bb30befb 100644
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -6,6 +6,8 @@ end
require "test/unit"
require "tempfile"
require "tmpdir"
+require "thread"
+require "io/nonblock"
class TestSocket_UNIXSocket < Test::Unit::TestCase
def test_fd_passing
@@ -102,6 +104,41 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
io_ary.each {|io| io.close if !io.closed? }
end
+ def test_fd_passing_race_condition
+ r1, w = IO.pipe
+ s1, s2 = UNIXSocket.pair
+ s1.nonblock = s2.nonblock = true
+ aoe = Thread.abort_on_exception
+ Thread.abort_on_exception = true
+ lock = Mutex.new
+ nr = 0
+ x = 2
+ y = 1000
+ begin
+ s1.send_io(nil)
+ rescue NotImplementedError
+ assert_raise(NotImplementedError) { s2.recv_io }
+ rescue TypeError
+ thrs = x.times.map do
+ Thread.new do
+ y.times do
+ s2.recv_io.close
+ lock.synchronize { nr += 1 }
+ end
+ end
+ end
+ (x * y).times { s1.send_io r1 }
+ thrs.each { |t| t.join }
+ assert_equal x * y, nr
+ ensure
+ Thread.abort_on_exception = aoe
+ s1.close
+ s2.close
+ w.close
+ r1.close
+ end
+ end
+
def test_sendmsg
return if !defined?(Socket::SCM_RIGHTS)
IO.pipe {|r1, w|