Skip to content

Commit

Permalink
Test socket
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 23, 2018
1 parent 42cd021 commit 2421c3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Other
- [net-telnet](#net-telnet)
- [omniauth-oauth2](#omniauth-oauth2)
- [reversed](#reversed)
- [socket](#socket)

## Statement Timeouts

Expand Down Expand Up @@ -1088,6 +1089,16 @@ Reversed.lookup("8.8.8.8", timeout: 1)

Returns `nil` on timeouts

### socket

```ruby
Socket.tcp(host, 80, connect_timeout: 1) do |sock|
# ...
end
```

Raises `Errno::ETIMEDOUT`

## Don’t see a library you use?

[Let us know](https://github.com/ankane/ruby-timeouts/issues/new). Even better, [create a pull request](https://github.com/ankane/ruby-timeouts/pulls) for it.
Expand Down
13 changes: 13 additions & 0 deletions test/socket_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_relative "test_helper"

class SocketTest < Minitest::Test
def test_connect
assert_timeout(Errno::ETIMEDOUT) do
Socket.tcp(connect_host, 80, connect_timeout: 1) do |sock|
sock.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n"
sock.close_write
puts sock.read
end
end
end
end

0 comments on commit 2421c3d

Please sign in to comment.