ruby/test/ruby/test_io_timeout.rb
Samuel Williams ea8a7287e2
Add support for sockaddr_un on Windows. (#6513)
* Windows: Fix warning about undefined if_indextoname()

* Windows: Fix UNIXSocket on MINGW and make .pair more reliable

* Windows: Use nonblock=true for read tests with scheduler

* Windows: Move socket detection from File.socket? to File.stat

Add S_IFSOCK to Windows and interpret reparse points accordingly.
Enable tests that work now.

* Windows: Use wide-char functions to UNIXSocket

This fixes behaviour with non-ASCII characters.
It also fixes deletion of temporary UNIXSocket.pair files.

* Windows: Add UNIXSocket tests for specifics of Windows impl.

* Windows: fix VC build due to missing _snwprintf

Avoid usage of _snwprintf, since it fails linking ruby.dll like so:

  linking shared-library x64-vcruntime140-ruby320.dll
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l

whereas linking miniruby.exe succeeds.

This patch uses snprintf on the UTF-8 string instead.

Also remove branch GetWindowsDirectoryW, since it doesn't work.

* Windows: Fix dangling symlink test failures

Co-authored-by: Lars Kanis <kanis@comcard.de>
2022-11-17 14:50:25 -08:00

58 lines
1 KiB
Ruby

# frozen_string_literal: false
require 'io/nonblock'
class TestIOTimeout < Test::Unit::TestCase
def with_pipe
omit "UNIXSocket is not defined!" unless defined?(UNIXSocket)
begin
i, o = UNIXSocket.pair
yield i, o
ensure
i.close
o.close
end
end
def test_timeout_attribute
with_pipe do |i, o|
assert_nil i.timeout
i.timeout = 10
assert_equal 10, i.timeout
assert_nil o.timeout
o.timeout = 20
assert_equal 20, o.timeout
assert_equal 10, i.timeout
end
end
def test_timeout_read_exception
with_pipe do |i, o|
i.timeout = 0.0001
assert_raise(IO::TimeoutError) {i.read}
end
end
def test_timeout_gets_exception
with_pipe do |i, o|
i.timeout = 0.0001
assert_raise(IO::TimeoutError) {i.gets}
end
end
def test_timeout_puts
with_pipe do |i, o|
i.timeout = 0.0001
o.puts("Hello World")
o.close
assert_equal "Hello World", i.gets.chomp
end
end
end