net_tcp_client 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d6906da5ebe4657343ec1175664ee2f42b359eb
4
- data.tar.gz: c816880d83f7d557390b00cbdfb5ed7c6a308512
3
+ metadata.gz: 729fc42e6f4a4480a26a68bbe970d6e7c79c4690
4
+ data.tar.gz: 6b9184a059415db496de138d6f54952deb916f91
5
5
  SHA512:
6
- metadata.gz: 5d1aafb91baf376f68f291d5d18bc9d5569522cc2b093baf337f525b8060d3e632f6799ee64d8da12fc4db533f01a29059ec63144403da29e0f9884cd0f1a623
7
- data.tar.gz: 32605f07229206ee29216ccfb5a2ecc74fe9c8c6d32459b7ec973fcd31f4541ab4ca710f148e6804254838265af364737449265908407f227100a96b761950af
6
+ metadata.gz: 6adaab1f407ef8fd782bb72d0c8fc8dcf42b3de34ae5b5d6b09e4000479ea89a394e8912f24f7c682af3b0493d6f417a557377e53c78ba539516ea0ea648a394
7
+ data.tar.gz: b597c576047fa6b7478c89aae82ee10ba0893dc49d3651548a57978f4e7236343eaaddcfeccc7e05b4113c9e77b65f2df0ac05babca3f54362051c75326141c2
@@ -3,13 +3,13 @@ module Net
3
3
  module Policy
4
4
  # Policy for connecting to servers in the order specified
5
5
  class Custom < Base
6
- def initialize(server_names, proc)
6
+ def initialize(server_names, block)
7
7
  super(server_names)
8
- @proc = proc
8
+ @block = block
9
9
  end
10
10
 
11
11
  # Calls the block once for each server, with the addresses in the order returned
12
- # by the supplied proc.
12
+ # by the supplied block.
13
13
  # The block must return a Net::TCPClient::Address instance,
14
14
  # or nil to stop trying to connect to servers
15
15
  #
@@ -18,7 +18,7 @@ module Net
18
18
  #
19
19
  # Example:
20
20
  # # Returns addresses in random order but without checking if a host name has been used before
21
- # policy.each_proc do |addresses, count|
21
+ # policy.each do |addresses, count|
22
22
  # # Return nil after the last address has been tried so that retry logic can take over
23
23
  # if count <= address.size
24
24
  # addresses.sample
@@ -26,7 +26,7 @@ module Net
26
26
  # end
27
27
  def each(&block)
28
28
  count = 1
29
- while address = @proc.call(addresses, count)
29
+ while address = @block.call(addresses, count)
30
30
  raise(ArgumentError, 'Proc must return Net::TCPClient::Address, or nil') unless address.is_a?(Net::TCPClient::Address) || address.nil?
31
31
  block.call(address)
32
32
  count += 1
@@ -59,7 +59,8 @@ module Net
59
59
  Errno::EPIPE,
60
60
  Errno::ETIMEDOUT,
61
61
  EOFError,
62
- Net::TCPClient::ConnectionTimeout
62
+ Net::TCPClient::ConnectionTimeout,
63
+ IOError
63
64
  ]
64
65
 
65
66
  # Return the array of errors that will result in an automatic connection retry
@@ -569,7 +570,7 @@ module Net
569
570
  end
570
571
  unless buffered
571
572
  socket.sync = true
572
- socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
573
+ socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
573
574
  end
574
575
 
575
576
  socket_connect(socket, address, connect_timeout)
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  class TCPClient #:nodoc
3
- VERSION = '2.0.0'
3
+ VERSION = '2.0.1'
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  require 'socket'
2
2
  require_relative 'test_helper'
3
3
  require_relative 'simple_tcp_server'
4
+ require 'securerandom'
4
5
 
5
6
  # Unit Test for Net::TCPClient
6
7
  class TCPClientTest < Minitest::Test
@@ -40,7 +41,8 @@ class TCPClientTest < Minitest::Test
40
41
 
41
42
  describe 'with server' do
42
43
  before do
43
- options = {port: 2000}
44
+ @port = 2000 + SecureRandom.random_number(1000)
45
+ options = {port: @port}
44
46
  if with_ssl
45
47
  options[:ssl] = {
46
48
  cert: OpenSSL::X509::Certificate.new(File.open(ssl_file_path('localhost-server.pem'))),
@@ -60,7 +62,7 @@ class TCPClientTest < Minitest::Test
60
62
  raise exc
61
63
  end
62
64
 
63
- @server_name = 'localhost:2000'
65
+ @server_name = "localhost:#{@port}"
64
66
  end
65
67
 
66
68
  after do
@@ -87,7 +89,7 @@ class TCPClientTest < Minitest::Test
87
89
  end
88
90
  assert_equal false, @client.close_on_error
89
91
  assert @client.alive?, 'The client connection is not alive after the read timed out with close_on_error: false'
90
- assert_equal "Timed out after #{@read_timeout} seconds trying to read from localhost[127.0.0.1]:2000", exception.message
92
+ assert_equal "Timed out after #{@read_timeout} seconds trying to read from localhost[127.0.0.1]:#{@port}", exception.message
91
93
  reply = read_bson_document(@client)
92
94
  assert_equal 'sleep', reply['result']
93
95
  @client.close
@@ -116,7 +118,7 @@ class TCPClientTest < Minitest::Test
116
118
  socket.user_data = {sequence: 1}
117
119
  end
118
120
  )
119
- assert_equal 'localhost[127.0.0.1]:2000', @client.address.to_s
121
+ assert_equal "localhost[127.0.0.1]:#{@port}", @client.address.to_s
120
122
  assert_equal 1, @client.user_data[:sequence]
121
123
 
122
124
  request = {'action' => 'test1'}
@@ -132,7 +134,7 @@ class TCPClientTest < Minitest::Test
132
134
  servers: ['localhost:1999', @server_name],
133
135
  read_timeout: 3
134
136
  )
135
- assert_equal 'localhost[127.0.0.1]:2000', @client.address.to_s
137
+ assert_equal "localhost[127.0.0.1]:#{@port}", @client.address.to_s
136
138
 
137
139
  request = {'action' => 'test1'}
138
140
  @client.write(BSON.serialize(request))
@@ -201,7 +203,7 @@ class TCPClientTest < Minitest::Test
201
203
  # Due to close_on_error: true, a timeout will close the connection
202
204
  # to prevent use of a socket connection in an inconsistent state
203
205
  assert_equal false, @client.alive?
204
- assert_equal "Timed out after #{@read_timeout} seconds trying to read from localhost[127.0.0.1]:2000", exception.message
206
+ assert_equal "Timed out after #{@read_timeout} seconds trying to read from localhost[127.0.0.1]:#{@port}", exception.message
205
207
  end
206
208
  end
207
209
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net_tcp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-06-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Net::TCPClient implements resilience features that many developers wish
14
14
  was already included in the standard Ruby libraries.