Ruby io_splice 4.4.2 - URL + doc updates
[ruby_io_splice.git] / test / test_io_splice_eintr.rb
blob057260f53168a26f4948b32ff2893c96889946ab
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       sleep 0.01
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     assert_equal 1, @usr1
34   end
35 end if defined?(RUBY_ENGINE)