From 0dc342de848a642ecce8db697b8fecd83a63e117 Mon Sep 17 00:00:00 2001 From: yugui Date: Mon, 25 Aug 2008 15:02:05 +0000 Subject: added tag v1_9_0_4 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- trunk/bootstraptest/test_io.rb | 94 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 trunk/bootstraptest/test_io.rb (limited to 'trunk/bootstraptest/test_io.rb') diff --git a/trunk/bootstraptest/test_io.rb b/trunk/bootstraptest/test_io.rb new file mode 100644 index 0000000000..c0b906fb4d --- /dev/null +++ b/trunk/bootstraptest/test_io.rb @@ -0,0 +1,94 @@ +assert_finish 5, %q{ + 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]' + +assert_finish 10, %q{ + begin + require "io/nonblock" + 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 + rescue LoadError + end +}, '[ruby-dev:32566]' + +assert_finish 1, %q{ + r, w = IO.pipe + Thread.new { + w << "ab" + sleep 0.1 + w << "ab" + } + r.gets("abab") +} + +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 +} + +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 +} + +assert_normal_exit %q{ + ARGF.set_encoding "foo" +} + +50.times do + assert_normal_exit %q{ + at_exit { p :foo } + + megacontent = "abc" * 12345678 + File.open("megasrc", "w") {|f| f << megacontent } + + 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 -- cgit v1.2.3