Sha256: 6469f1a99934443214851816c665444f134bf96890e0691fca01a5cca6b2681b
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
require_relative '../test_helper' class Net::TCPClient::Policy::RandomTest < Minitest::Test describe Net::TCPClient::Policy::Random do describe '#each' do it 'must return one server, once' do servers = ['localhost:80'] policy = Net::TCPClient::Policy::Random.new(servers) collected = [] policy.each { |address| collected << address } assert_equal 1, collected.size address = collected.first assert_equal 80, address.port assert_equal 'localhost', address.host_name assert_equal '127.0.0.1', address.ip_address end it 'must return the servers in random order' do servers = %w(localhost:80 127.0.0.1:2000 lvh.me:2100) policy = Net::TCPClient::Policy::Random.new(servers) names = [] # It is possible the random order is the supplied order. # Keep retrying until the order is different. 3.times do policy.each { |address| names << address.host_name } break if names != %w(localhost 127.0.0.1 lvh.me) names = [] end refute_equal %w(localhost 127.0.0.1 lvh.me), names assert_equal %w(localhost 127.0.0.1 lvh.me).sort, names.sort end it 'must handle an empty list of servers' do servers = [] policy = Net::TCPClient::Policy::Random.new(servers) names = [] policy.each { |address| names << address.host_name } assert_equal [], names end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
net_tcp_client-2.2.0 | test/policy/random_policy_test.rb |