0002-test_io-add-test-for-copy_stream-failing-on-EINTR.patch

test case, may not be portable... - Eric Wong, 05/13/2011 06:56 AM

Download (1.75 KB)

View differences:

test/ruby/test_io.rb
78 78
    }
79 79
  end
80 80

  
81
  def trapping_usr1
82
    @usr1_rcvd  = 0
83
    trap(:USR1) { @usr1_rcvd += 1 }
84
    yield
85
    ensure
86
      trap(:USR1, "DEFAULT")
87
  end
88

  
81 89
  def test_pipe
82 90
    r, w = IO.pipe
83 91
    assert_instance_of(IO, r)
......
594 602
          result = t.value
595 603
          assert_equal(megacontent, result)
596 604
        }
605
        with_socketpair {|s1, s2|
606
          begin
607
            s1.nonblock = true
608
          rescue Errno::EBADF
609
            skip "nonblocking IO for pipe is not implemented"
610
          end
611
          trapping_usr1 do
612
            nr = 10
613
            pid = fork do
614
              s1.close
615
              IO.select([s2])
616
              Process.kill(:USR1, Process.ppid)
617
              s2.read
618
            end
619
            s2.close
620
            nr.times do
621
              assert_equal megacontent.bytesize, IO.copy_stream("megasrc", s1)
622
            end
623
            assert_equal(1, @usr1_rcvd)
624
            s1.close
625
            _, status = Process.waitpid2(pid)
626
            assert status.success?, status.inspect
627
          end
628
        }
597 629
      end
598 630
    }
599 631
  end