steam-condenser 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/Gemfile.lock +30 -0
  2. data/LICENSE +1 -1
  3. data/README.md +4 -3
  4. data/lib/steam-condenser/version.rb +2 -2
  5. data/lib/steam/community/alien_swarm/alien_swarm_mission.rb +24 -22
  6. data/lib/steam/community/alien_swarm/alien_swarm_stats.rb +66 -65
  7. data/lib/steam/community/alien_swarm/alien_swarm_weapon.rb +6 -6
  8. data/lib/steam/community/app_news.rb +2 -2
  9. data/lib/steam/community/css/css_map.rb +4 -4
  10. data/lib/steam/community/css/css_stats.rb +43 -43
  11. data/lib/steam/community/css/css_weapon.rb +5 -5
  12. data/lib/steam/community/defense_grid/defense_grid_stats.rb +36 -35
  13. data/lib/steam/community/dods/dods_class.rb +14 -14
  14. data/lib/steam/community/dods/dods_stats.rb +5 -4
  15. data/lib/steam/community/dods/dods_weapon.rb +6 -6
  16. data/lib/steam/community/game_achievement.rb +38 -31
  17. data/lib/steam/community/game_inventory.rb +6 -6
  18. data/lib/steam/community/game_leaderboard.rb +34 -32
  19. data/lib/steam/community/game_leaderboard_entry.rb +6 -6
  20. data/lib/steam/community/game_stats.rb +39 -65
  21. data/lib/steam/community/game_weapon.rb +2 -2
  22. data/lib/steam/community/l4d/abstract_l4d_stats.rb +54 -49
  23. data/lib/steam/community/l4d/abstract_l4d_weapon.rb +7 -6
  24. data/lib/steam/community/l4d/l4d2_map.rb +10 -10
  25. data/lib/steam/community/l4d/l4d2_stats.rb +33 -33
  26. data/lib/steam/community/l4d/l4d2_weapon.rb +8 -7
  27. data/lib/steam/community/l4d/l4d_explosive.rb +5 -4
  28. data/lib/steam/community/l4d/l4d_map.rb +8 -7
  29. data/lib/steam/community/l4d/l4d_stats.rb +7 -7
  30. data/lib/steam/community/l4d/l4d_weapon.rb +5 -4
  31. data/lib/steam/community/portal2/portal2_stats.rb +3 -3
  32. data/lib/steam/community/steam_game.rb +106 -16
  33. data/lib/steam/community/steam_group.rb +51 -40
  34. data/lib/steam/community/steam_id.rb +119 -87
  35. data/lib/steam/community/tf2/tf2_class.rb +14 -14
  36. data/lib/steam/community/tf2/tf2_class_factory.rb +2 -2
  37. data/lib/steam/community/tf2/tf2_engineer.rb +5 -7
  38. data/lib/steam/community/tf2/tf2_golden_wrench.rb +1 -1
  39. data/lib/steam/community/tf2/tf2_medic.rb +4 -6
  40. data/lib/steam/community/tf2/tf2_sniper.rb +3 -5
  41. data/lib/steam/community/tf2/tf2_spy.rb +10 -6
  42. data/lib/steam/community/tf2/tf2_stats.rb +15 -7
  43. data/lib/steam/community/web_api.rb +15 -1
  44. data/lib/steam/community/xml_data.rb +17 -0
  45. data/lib/steam/servers/game_server.rb +4 -4
  46. data/lib/steam/servers/master_server.rb +2 -2
  47. data/lib/steam/servers/source_server.rb +0 -2
  48. data/lib/steam/sockets/goldsrc_socket.rb +2 -2
  49. data/lib/steam/steam_player.rb +2 -2
  50. data/steam-condenser.gemspec +3 -2
  51. data/test/helper.rb +10 -2
  52. data/test/steam/communtiy/test_steam_group.rb +4 -4
  53. data/test/steam/communtiy/test_steam_id.rb +28 -2
  54. data/test/steam/communtiy/test_web_api.rb +2 -2
  55. data/test/steam/packets/test_steam_packet.rb +37 -0
  56. data/test/steam/servers/test_game_server.rb +296 -308
  57. data/test/steam/servers/test_goldsrc_server.rb +59 -59
  58. data/test/steam/servers/test_master_server.rb +131 -131
  59. data/test/steam/servers/test_server.rb +72 -72
  60. data/test/steam/servers/test_source_server.rb +126 -140
  61. data/test/steam/sockets/test_master_server_socket.rb +1 -0
  62. metadata +39 -19
@@ -1,59 +1,59 @@
1
- # This code is free software; you can redistribute it and/or modify it under
2
- # the terms of the new BSD License.
3
- #
4
- # Copyright (c) 2011, Sebastian Staudt
5
-
6
- require 'helper'
7
- require 'steam/servers/goldsrc_server'
8
-
9
- class TestGoldSrcServer < Test::Unit::TestCase
10
-
11
- context 'The user' do
12
-
13
- should 'be able to get a master server for GoldSrc servers' do
14
- master = mock
15
- MasterServer.expects(:new).with(*MasterServer::GOLDSRC_MASTER_SERVER).
16
- returns master
17
-
18
- assert_equal master, GoldSrcServer.master
19
- end
20
-
21
- end
22
-
23
- context 'A GoldSrc server' do
24
-
25
- setup do
26
- Socket.stubs(:getaddrinfo).
27
- with('goldsrc', 27015, Socket::AF_INET, Socket::SOCK_DGRAM).
28
- returns [[nil, nil, 'goldsrc', '127.0.0.1']]
29
-
30
- @server = GoldSrcServer.new 'goldsrc', 27015
31
- end
32
-
33
- should 'create a client socket upon initialization' do
34
- socket = mock
35
- GoldSrcSocket.expects(:new).with('127.0.0.1', 27015, false).returns socket
36
-
37
- @server.init_socket
38
-
39
- assert_same socket, @server.instance_variable_get(:@socket)
40
- end
41
-
42
- should 'save the RCON password for further use' do
43
- assert @server.rcon_auth 'password'
44
- assert_equal 'password', @server.instance_variable_get(:@rcon_password)
45
- end
46
-
47
- should 'send RCON commands with the password' do
48
- socket = mock
49
- socket.expects(:rcon_exec).with('password', 'command').returns 'test '
50
-
51
- @server.instance_variable_set :@rcon_password, 'password'
52
- @server.instance_variable_set :@socket, socket
53
-
54
- assert_equal 'test', @server.rcon_exec('command')
55
- end
56
-
57
- end
58
-
59
- end
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2011, Sebastian Staudt
5
+
6
+ require 'helper'
7
+ require 'steam/servers/goldsrc_server'
8
+
9
+ class TestGoldSrcServer < Test::Unit::TestCase
10
+
11
+ context 'The user' do
12
+
13
+ should 'be able to get a master server for GoldSrc servers' do
14
+ master = mock
15
+ MasterServer.expects(:new).with(*MasterServer::GOLDSRC_MASTER_SERVER).
16
+ returns master
17
+
18
+ assert_equal master, GoldSrcServer.master
19
+ end
20
+
21
+ end
22
+
23
+ context 'A GoldSrc server' do
24
+
25
+ setup do
26
+ Socket.stubs(:getaddrinfo).
27
+ with('goldsrc', 27015, Socket::AF_INET, Socket::SOCK_DGRAM).
28
+ returns [[nil, nil, 'goldsrc', '127.0.0.1']]
29
+
30
+ @server = GoldSrcServer.new 'goldsrc', 27015
31
+ end
32
+
33
+ should 'create a client socket upon initialization' do
34
+ socket = mock
35
+ GoldSrcSocket.expects(:new).with('127.0.0.1', 27015, false).returns socket
36
+
37
+ @server.init_socket
38
+
39
+ assert_same socket, @server.instance_variable_get(:@socket)
40
+ end
41
+
42
+ should 'save the RCON password for further use' do
43
+ assert @server.rcon_auth 'password'
44
+ assert_equal 'password', @server.instance_variable_get(:@rcon_password)
45
+ end
46
+
47
+ should 'send RCON commands with the password' do
48
+ socket = mock
49
+ socket.expects(:rcon_exec).with('password', 'command').returns 'test '
50
+
51
+ @server.instance_variable_set :@rcon_password, 'password'
52
+ @server.instance_variable_set :@socket, socket
53
+
54
+ assert_equal 'test', @server.rcon_exec('command')
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -1,131 +1,131 @@
1
- # This code is free software; you can redistribute it and/or modify it under
2
- # the terms of the new BSD License.
3
- #
4
- # Copyright (c) 2011, Sebastian Staudt
5
-
6
- require 'helper'
7
- require 'steam/servers/master_server'
8
-
9
- class TestMasterServer < Test::Unit::TestCase
10
-
11
- context 'The user' do
12
-
13
- should 'be able to set the number of retries' do
14
- MasterServer.retries = 5
15
-
16
- assert_equal 5, MasterServer.send(:class_variable_get, :@@retries)
17
- end
18
-
19
- end
20
-
21
- context 'A master server' do
22
-
23
- setup do
24
- Socket.stubs(:getaddrinfo).
25
- with('master', 27015, Socket::AF_INET, Socket::SOCK_DGRAM).
26
- returns [[nil, nil, 'master', '127.0.0.1']]
27
-
28
- @server = MasterServer.new 'master', 27015
29
- end
30
-
31
- should 'create a client socket upon initialization' do
32
- socket = mock
33
- MasterServerSocket.expects(:new).with('127.0.0.1', 27015).returns socket
34
-
35
- @server.init_socket
36
-
37
- assert_same socket, @server.instance_variable_get(:@socket)
38
- end
39
-
40
- should 'be able to get a challenge' do
41
- reply = mock :challenge => 1234
42
-
43
- socket = @server.instance_variable_get :@socket
44
- socket.expects(:send).with { |packet| packet.is_a? C2M_CHECKMD5_Packet }
45
- socket.expects(:reply).returns reply
46
-
47
- assert_equal 1234, @server.challenge
48
- end
49
-
50
- should 'be able to get a list of servers' do
51
- reply1 = mock :servers => %w{127.0.0.1:27015 127.0.0.2:27015 127.0.0.3:27015}
52
- reply2 = mock :servers => %w{127.0.0.4:27015 0.0.0.0:0}
53
-
54
- socket = @server.instance_variable_get :@socket
55
- socket.expects(:send).with do |packet|
56
- packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
57
- packet.instance_variable_get(:@filter) == 'filter' &&
58
- packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
59
- packet.instance_variable_get(:@start_ip) == '0.0.0.0:0'
60
- end
61
- socket.expects(:send).with do |packet|
62
- packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
63
- packet.instance_variable_get(:@filter) == 'filter' &&
64
- packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
65
- packet.instance_variable_get(:@start_ip) == '127.0.0.3:27015'
66
- end
67
- socket.expects(:reply).times(2).returns(reply1).returns reply2
68
-
69
- servers = [['127.0.0.1', '27015'], ['127.0.0.2', '27015'], ['127.0.0.3', '27015'], ['127.0.0.4', '27015']]
70
- assert_equal servers, @server.servers(MasterServer::REGION_EUROPE, 'filter')
71
- end
72
-
73
- should 'be able to send a heartbeat' do
74
- reply1 = mock
75
- reply2 = mock
76
-
77
- socket = @server.instance_variable_get :@socket
78
- socket.expects(:send).with { |packet| packet.is_a? S2M_HEARTBEAT2_Packet }
79
- socket.expects(:reply).times(3).returns(reply1).returns(reply2).then.
80
- raises SteamCondenser::TimeoutError
81
-
82
- data = { :challenge => 1234 }
83
- assert_equal [reply1, reply2], @server.send_heartbeat(data)
84
- end
85
-
86
- should 'not timeout if returning servers is forced' do
87
- MasterServer.retries = 1
88
-
89
- reply = mock :servers => %w{127.0.0.1:27015 127.0.0.2:27015 127.0.0.3:27015}
90
-
91
- socket = @server.instance_variable_get :@socket
92
- socket.expects(:send).with do |packet|
93
- packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
94
- packet.instance_variable_get(:@filter) == 'filter' &&
95
- packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
96
- packet.instance_variable_get(:@start_ip) == '0.0.0.0:0'
97
- end
98
- socket.expects(:send).with do |packet|
99
- packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
100
- packet.instance_variable_get(:@filter) == 'filter' &&
101
- packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
102
- packet.instance_variable_get(:@start_ip) == '127.0.0.3:27015'
103
- end
104
- socket.expects(:reply).times(2).returns(reply).then.
105
- raises(SteamCondenser::TimeoutError)
106
-
107
- servers = [['127.0.0.1', '27015'], ['127.0.0.2', '27015'], ['127.0.0.3', '27015']]
108
- assert_equal servers, @server.servers(MasterServer::REGION_EUROPE, 'filter', true)
109
- end
110
-
111
- should 'timeout after a predefined number of retries' do
112
- retries = rand(4) + 1
113
- MasterServer.retries = retries
114
-
115
- socket = @server.instance_variable_get :@socket
116
- socket.expects(:send).times(retries).with do |packet|
117
- packet.is_a? A2M_GET_SERVERS_BATCH2_Packet
118
- packet.instance_variable_get(:@filter) == ''
119
- packet.instance_variable_get(:@region_code) == MasterServer::REGION_ALL
120
- packet.instance_variable_get(:@start_ip) == '0.0.0.0:0'
121
- end
122
- socket.expects(:reply).times(retries).raises SteamCondenser::TimeoutError
123
-
124
- assert_raises SteamCondenser::TimeoutError do
125
- @server.servers
126
- end
127
- end
128
-
129
- end
130
-
131
- end
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2011, Sebastian Staudt
5
+
6
+ require 'helper'
7
+ require 'steam/servers/master_server'
8
+
9
+ class TestMasterServer < Test::Unit::TestCase
10
+
11
+ context 'The user' do
12
+
13
+ should 'be able to set the number of retries' do
14
+ MasterServer.retries = 5
15
+
16
+ assert_equal 5, MasterServer.send(:class_variable_get, :@@retries)
17
+ end
18
+
19
+ end
20
+
21
+ context 'A master server' do
22
+
23
+ setup do
24
+ Socket.stubs(:getaddrinfo).
25
+ with('master', 27015, Socket::AF_INET, Socket::SOCK_DGRAM).
26
+ returns [[nil, nil, 'master', '127.0.0.1']]
27
+
28
+ @server = MasterServer.new 'master', 27015
29
+ end
30
+
31
+ should 'create a client socket upon initialization' do
32
+ socket = mock
33
+ MasterServerSocket.expects(:new).with('127.0.0.1', 27015).returns socket
34
+
35
+ @server.init_socket
36
+
37
+ assert_same socket, @server.instance_variable_get(:@socket)
38
+ end
39
+
40
+ should 'be able to get a challenge' do
41
+ reply = mock :challenge => 1234
42
+
43
+ socket = @server.instance_variable_get :@socket
44
+ socket.expects(:send).with { |packet| packet.is_a? C2M_CHECKMD5_Packet }
45
+ socket.expects(:reply).returns reply
46
+
47
+ assert_equal 1234, @server.challenge
48
+ end
49
+
50
+ should 'be able to get a list of servers' do
51
+ reply1 = mock :servers => %w{127.0.0.1:27015 127.0.0.2:27015 127.0.0.3:27015}
52
+ reply2 = mock :servers => %w{127.0.0.4:27015 0.0.0.0:0}
53
+
54
+ socket = @server.instance_variable_get :@socket
55
+ socket.expects(:send).with do |packet|
56
+ packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
57
+ packet.instance_variable_get(:@filter) == 'filter' &&
58
+ packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
59
+ packet.instance_variable_get(:@start_ip) == '0.0.0.0:0'
60
+ end
61
+ socket.expects(:send).with do |packet|
62
+ packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
63
+ packet.instance_variable_get(:@filter) == 'filter' &&
64
+ packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
65
+ packet.instance_variable_get(:@start_ip) == '127.0.0.3:27015'
66
+ end
67
+ socket.expects(:reply).times(2).returns(reply1).returns reply2
68
+
69
+ servers = [['127.0.0.1', '27015'], ['127.0.0.2', '27015'], ['127.0.0.3', '27015'], ['127.0.0.4', '27015']]
70
+ assert_equal servers, @server.servers(MasterServer::REGION_EUROPE, 'filter')
71
+ end
72
+
73
+ should 'be able to send a heartbeat' do
74
+ reply1 = mock
75
+ reply2 = mock
76
+
77
+ socket = @server.instance_variable_get :@socket
78
+ socket.expects(:send).with { |packet| packet.is_a? S2M_HEARTBEAT2_Packet }
79
+ socket.expects(:reply).times(3).returns(reply1).returns(reply2).then.
80
+ raises SteamCondenser::TimeoutError
81
+
82
+ data = { :challenge => 1234 }
83
+ assert_equal [reply1, reply2], @server.send_heartbeat(data)
84
+ end
85
+
86
+ should 'not timeout if returning servers is forced' do
87
+ MasterServer.retries = 1
88
+
89
+ reply = mock :servers => %w{127.0.0.1:27015 127.0.0.2:27015 127.0.0.3:27015}
90
+
91
+ socket = @server.instance_variable_get :@socket
92
+ socket.expects(:send).with do |packet|
93
+ packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
94
+ packet.instance_variable_get(:@filter) == 'filter' &&
95
+ packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
96
+ packet.instance_variable_get(:@start_ip) == '0.0.0.0:0'
97
+ end
98
+ socket.expects(:send).with do |packet|
99
+ packet.is_a?(A2M_GET_SERVERS_BATCH2_Packet) &&
100
+ packet.instance_variable_get(:@filter) == 'filter' &&
101
+ packet.instance_variable_get(:@region_code) == MasterServer::REGION_EUROPE &&
102
+ packet.instance_variable_get(:@start_ip) == '127.0.0.3:27015'
103
+ end
104
+ socket.expects(:reply).times(2).returns(reply).then.
105
+ raises(SteamCondenser::TimeoutError)
106
+
107
+ servers = [['127.0.0.1', '27015'], ['127.0.0.2', '27015'], ['127.0.0.3', '27015']]
108
+ assert_equal servers, @server.servers(MasterServer::REGION_EUROPE, 'filter', true)
109
+ end
110
+
111
+ should 'timeout after a predefined number of retries' do
112
+ retries = rand(4) + 1
113
+ MasterServer.retries = retries
114
+
115
+ socket = @server.instance_variable_get :@socket
116
+ socket.expects(:send).times(retries).with do |packet|
117
+ packet.is_a? A2M_GET_SERVERS_BATCH2_Packet
118
+ packet.instance_variable_get(:@filter) == ''
119
+ packet.instance_variable_get(:@region_code) == MasterServer::REGION_ALL
120
+ packet.instance_variable_get(:@start_ip) == '0.0.0.0:0'
121
+ end
122
+ socket.expects(:reply).times(retries).raises SteamCondenser::TimeoutError
123
+
124
+ assert_raises SteamCondenser::TimeoutError do
125
+ @server.servers
126
+ end
127
+ end
128
+
129
+ end
130
+
131
+ end
@@ -1,72 +1,72 @@
1
- # This code is free software; you can redistribute it and/or modify it under
2
- # the terms of the new BSD License.
3
- #
4
- # Copyright (c) 2011, Sebastian Staudt
5
-
6
- require 'helper'
7
- require 'steam/servers/server'
8
-
9
- class TestServer < Test::Unit::TestCase
10
-
11
- context 'A generic server' do
12
-
13
- class GenericServer
14
- include Server
15
- end
16
-
17
- should 'split IP and port combinations' do
18
- Socket.expects(:getaddrinfo).
19
- with('127.0.0.1', '27015', Socket::AF_INET, Socket::SOCK_DGRAM).
20
- returns []
21
- Socket.expects(:getaddrinfo).
22
- with('someserver', '27015', Socket::AF_INET, Socket::SOCK_DGRAM).
23
- returns []
24
-
25
- GenericServer.new '127.0.0.1:27015'
26
- GenericServer.new 'someserver:27015'
27
- end
28
-
29
- should 'resolve multiple DNS names' do
30
- Socket.expects(:getaddrinfo).
31
- with('someserver', 27015, Socket::AF_INET, Socket::SOCK_DGRAM).
32
- returns [
33
- [nil, nil, 'someserver', '127.0.0.1'],
34
- [nil, nil, 'someserver2', '127.0.0.2']
35
- ]
36
-
37
- server = GenericServer.new 'someserver', 27015
38
-
39
- assert_equal %w{someserver someserver2}, server.host_names
40
- assert_equal %w{127.0.0.1 127.0.0.2}, server.ip_addresses
41
- end
42
-
43
- should 'rotate through multiple IP addresses' do
44
- Socket.stubs(:getaddrinfo).returns []
45
-
46
- server = GenericServer.new 'someserver'
47
- server.instance_variable_set :@ip_addresses, %w{127.0.0.1 127.0.0.2}
48
- server.instance_variable_set :@ip_address, '127.0.0.1'
49
- server.expects(:init_socket).twice
50
-
51
- assert_not server.rotate_ip
52
- assert_equal '127.0.0.2', server.instance_variable_get(:@ip_address)
53
- assert server.rotate_ip
54
- assert_equal '127.0.0.1', server.instance_variable_get(:@ip_address)
55
- end
56
-
57
- should 'allow a failsafe block to execute with IP fallback' do
58
- Socket.stubs(:getaddrinfo).returns []
59
- block = Proc.new { raise 'error' }
60
-
61
- server = GenericServer.new 'someserver'
62
- server.expects(:rotate_ip).twice.returns(false).then.returns(true)
63
-
64
- error = assert_raises RuntimeError do
65
- server.send :failsafe, &block
66
- end
67
- assert_equal 'error', error.message
68
- end
69
-
70
- end
71
-
72
- end
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2011, Sebastian Staudt
5
+
6
+ require 'helper'
7
+ require 'steam/servers/server'
8
+
9
+ class TestServer < Test::Unit::TestCase
10
+
11
+ context 'A generic server' do
12
+
13
+ class GenericServer
14
+ include Server
15
+ end
16
+
17
+ should 'split IP and port combinations' do
18
+ Socket.expects(:getaddrinfo).
19
+ with('127.0.0.1', '27015', Socket::AF_INET, Socket::SOCK_DGRAM).
20
+ returns []
21
+ Socket.expects(:getaddrinfo).
22
+ with('someserver', '27015', Socket::AF_INET, Socket::SOCK_DGRAM).
23
+ returns []
24
+
25
+ GenericServer.new '127.0.0.1:27015'
26
+ GenericServer.new 'someserver:27015'
27
+ end
28
+
29
+ should 'resolve multiple DNS names' do
30
+ Socket.expects(:getaddrinfo).
31
+ with('someserver', 27015, Socket::AF_INET, Socket::SOCK_DGRAM).
32
+ returns [
33
+ [nil, nil, 'someserver', '127.0.0.1'],
34
+ [nil, nil, 'someserver2', '127.0.0.2']
35
+ ]
36
+
37
+ server = GenericServer.new 'someserver', 27015
38
+
39
+ assert_equal %w{someserver someserver2}, server.host_names
40
+ assert_equal %w{127.0.0.1 127.0.0.2}, server.ip_addresses
41
+ end
42
+
43
+ should 'rotate through multiple IP addresses' do
44
+ Socket.stubs(:getaddrinfo).returns []
45
+
46
+ server = GenericServer.new 'someserver'
47
+ server.instance_variable_set :@ip_addresses, %w{127.0.0.1 127.0.0.2}
48
+ server.instance_variable_set :@ip_address, '127.0.0.1'
49
+ server.expects(:init_socket).twice
50
+
51
+ assert_not server.rotate_ip
52
+ assert_equal '127.0.0.2', server.instance_variable_get(:@ip_address)
53
+ assert server.rotate_ip
54
+ assert_equal '127.0.0.1', server.instance_variable_get(:@ip_address)
55
+ end
56
+
57
+ should 'allow a failsafe block to execute with IP fallback' do
58
+ Socket.stubs(:getaddrinfo).returns []
59
+ block = Proc.new { raise 'error' }
60
+
61
+ server = GenericServer.new 'someserver'
62
+ server.expects(:rotate_ip).twice.returns(false).then.returns(true)
63
+
64
+ error = assert_raises RuntimeError do
65
+ server.send :failsafe, &block
66
+ end
67
+ assert_equal 'error', error.message
68
+ end
69
+
70
+ end
71
+
72
+ end