2007-11-27 17:53:28 -05:00
|
|
|
assert_finish 5, %q{
|
2007-11-25 20:20:48 -05:00
|
|
|
r, w = IO.pipe
|
|
|
|
t1 = Thread.new { r.sysread(1) }
|
|
|
|
t2 = Thread.new { r.sysread(1) }
|
|
|
|
sleep 0.1
|
|
|
|
w.write "a"
|
|
|
|
sleep 0.1
|
|
|
|
w.write "a"
|
|
|
|
}, '[ruby-dev:31866]'
|
2007-12-21 04:43:49 -05:00
|
|
|
|
|
|
|
assert_finish 10, %q{
|
2007-12-21 16:35:08 -05:00
|
|
|
begin
|
|
|
|
require "io/nonblock"
|
2009-07-21 12:36:41 -04:00
|
|
|
require "timeout"
|
|
|
|
timeout(3) do
|
|
|
|
r, w = IO.pipe
|
|
|
|
w.nonblock = true
|
|
|
|
w.write_nonblock("a" * 100000)
|
|
|
|
w.nonblock = false
|
|
|
|
t1 = Thread.new { w.write("b" * 4096) }
|
|
|
|
t2 = Thread.new { w.write("c" * 4096) }
|
|
|
|
sleep 0.5
|
|
|
|
r.sysread(4096).length
|
|
|
|
sleep 0.5
|
|
|
|
r.sysread(4096).length
|
|
|
|
t1.join
|
|
|
|
t2.join
|
|
|
|
end
|
|
|
|
rescue LoadError, TimeoutError
|
2007-12-21 16:35:08 -05:00
|
|
|
end
|
2007-12-21 04:43:49 -05:00
|
|
|
}, '[ruby-dev:32566]'
|
2007-12-25 04:52:52 -05:00
|
|
|
|
|
|
|
assert_finish 1, %q{
|
|
|
|
r, w = IO.pipe
|
|
|
|
Thread.new {
|
|
|
|
w << "ab"
|
|
|
|
sleep 0.1
|
|
|
|
w << "ab"
|
|
|
|
}
|
2007-12-26 01:28:42 -05:00
|
|
|
r.gets("abab")
|
2007-12-25 04:52:52 -05:00
|
|
|
}
|
2008-02-07 02:40:25 -05:00
|
|
|
|
|
|
|
assert_equal 'ok', %q{
|
|
|
|
require 'tmpdir'
|
|
|
|
begin
|
|
|
|
tmpname = "#{Dir.tmpdir}/ruby-btest-#{$$}-#{rand(0x100000000).to_s(36)}"
|
|
|
|
rw = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL)
|
|
|
|
rescue Errno::EEXIST
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
save = STDIN.dup
|
|
|
|
STDIN.reopen(rw)
|
|
|
|
STDIN.reopen(save)
|
|
|
|
rw.close
|
|
|
|
File.unlink(tmpname)
|
|
|
|
:ok
|
|
|
|
}
|
2008-02-14 07:01:50 -05:00
|
|
|
|
|
|
|
assert_equal 'ok', %q{
|
|
|
|
require 'tmpdir'
|
|
|
|
begin
|
|
|
|
tmpname = "#{Dir.tmpdir}/ruby-btest-#{$$}-#{rand(0x100000000).to_s(36)}"
|
|
|
|
rw = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL)
|
|
|
|
rescue Errno::EEXIST
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
save = STDIN.dup
|
|
|
|
STDIN.reopen(rw)
|
|
|
|
STDIN.print "a"
|
|
|
|
STDIN.reopen(save)
|
|
|
|
rw.close
|
|
|
|
File.unlink(tmpname)
|
|
|
|
:ok
|
|
|
|
}
|
2008-02-21 00:47:12 -05:00
|
|
|
|
|
|
|
assert_normal_exit %q{
|
|
|
|
ARGF.set_encoding "foo"
|
|
|
|
}
|
2008-07-11 07:51:39 -04:00
|
|
|
|
|
|
|
50.times do
|
|
|
|
assert_normal_exit %q{
|
|
|
|
at_exit { p :foo }
|
|
|
|
|
|
|
|
megacontent = "abc" * 12345678
|
2008-08-28 06:05:35 -04:00
|
|
|
#File.open("megasrc", "w") {|f| f << megacontent }
|
2008-07-11 07:51:39 -04:00
|
|
|
|
|
|
|
Thread.new { sleep rand*0.2; Process.kill(:INT, $$) }
|
|
|
|
|
|
|
|
r1, w1 = IO.pipe
|
|
|
|
r2, w2 = IO.pipe
|
|
|
|
t1 = Thread.new { w1 << megacontent; w1.close }
|
|
|
|
t2 = Thread.new { r2.read }
|
|
|
|
IO.copy_stream(r1, w2) rescue nil
|
|
|
|
r2.close; w2.close
|
|
|
|
r1.close; w1.close
|
|
|
|
}, '', ["INT"] or break
|
|
|
|
end
|
2009-04-26 05:44:35 -04:00
|
|
|
|
|
|
|
assert_normal_exit %q{
|
|
|
|
r, w = IO.pipe
|
|
|
|
STDOUT.reopen(w)
|
|
|
|
STDOUT.reopen(__FILE__, "r")
|
|
|
|
}, '[ruby-dev:38131]'
|