EINTR test only works under 1.9
[ruby_io_splice.git] / test / test_io_splice_eintr.rb
blob7f81ff23eff65578e06f6b8284a9fc59a32d0df5
1 # -*- encoding: binary -*-
2 require 'test/unit'
3 require 'tempfile'
4 require 'socket'
5 require 'io/nonblock'
6 require 'timeout'
7 $-w = true
8 require 'io/splice'
9 Thread.abort_on_exception = true
11 class Test_IO_Splice_EINTR < Test::Unit::TestCase
12   def setup
13     @usr1 = 0
14     trap(:USR1) { @usr1 += 1 }
15   end
17   def teardown
18     trap(:USR1, "DEFAULT")
19   end
21   def test_EINTR_splice_read
22     rd, wr = IO.pipe
23     tmp = Tempfile.new 'splice-read'
24     main = Thread.current
25     Thread.new do
26       Thread.pass until main.stop?
27       Process.kill(:USR1, $$)
28       sleep 0.01
29       wr.write "HI"
30     end
31     nr = IO.splice rd, nil, tmp, nil, 666
32     assert_equal 2, nr
33   end
34 end if defined?(RUBY_ENGINE) &&
35        RUBY_ENGINE == "ruby" &&
36        RUBY_VERSION.to_f >= 1.9