build_status_server 0.11 → 0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock
CHANGED
@@ -147,13 +147,20 @@ The address configured is not available (#{address})
|
|
147
147
|
STDERR.puts "Error: #{ex} while trying to send #{light}"
|
148
148
|
retry unless attempts > tcp_client["attempts"]
|
149
149
|
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => ex
|
150
|
+
wait = wait_for(attempts)
|
150
151
|
STDERR.puts "Error: #{ex} while trying to send #{light}"
|
151
|
-
STDERR.puts "Will wait for
|
152
|
-
sleep 2
|
152
|
+
STDERR.puts "Will wait for #{wait} seconds and try again..."
|
153
|
+
# sleep 2 seconds the first attempt, 4 the next, 8 the following...
|
154
|
+
sleep wait
|
153
155
|
retry unless attempts > tcp_client["attempts"]
|
154
156
|
ensure
|
155
157
|
client.close if client
|
156
158
|
end
|
157
159
|
end
|
160
|
+
|
161
|
+
def wait_for(attempt = 1)
|
162
|
+
return 60 if attempt > 5 # Cap at one minute wait
|
163
|
+
2**attempt
|
164
|
+
end
|
158
165
|
end
|
159
166
|
end
|
@@ -352,13 +352,15 @@ describe BuildStatusServer::Server do
|
|
352
352
|
it "should not connect and retry 2 times" do
|
353
353
|
STDERR.should_receive(:puts).with("Error: Connection refused while trying to send fail")
|
354
354
|
STDERR.should_receive(:puts).with("Error: No route to host while trying to send fail")
|
355
|
-
STDERR.should_receive(:puts).
|
355
|
+
STDERR.should_receive(:puts).with("Will wait for 2 seconds and try again...")
|
356
|
+
STDERR.should_receive(:puts).with("Will wait for 4 seconds and try again...")
|
356
357
|
|
357
358
|
TCPSocket.should_receive(:new).with("host", "port").and_raise(Errno::ECONNREFUSED)
|
358
359
|
TCPSocket.should_receive(:new).with("host", "port").and_raise(Errno::EHOSTUNREACH)
|
359
360
|
TCPSocket.should_receive(:new).with("host", "port").and_return(client)
|
360
361
|
|
361
|
-
server.should_receive(:sleep).
|
362
|
+
server.should_receive(:sleep).with(2)
|
363
|
+
server.should_receive(:sleep).with(4)
|
362
364
|
|
363
365
|
client.should_receive(:print).with("GET fail HTTP/1.0\n\n")
|
364
366
|
|
@@ -424,6 +426,18 @@ describe BuildStatusServer::Server do
|
|
424
426
|
end
|
425
427
|
end
|
426
428
|
|
429
|
+
describe "#wait_for" do
|
430
|
+
it "should return 2**n for each attempt n up to 5" do
|
431
|
+
server.send(:wait_for, 1).should == 2
|
432
|
+
server.send(:wait_for, 5).should == 32
|
433
|
+
end
|
434
|
+
|
435
|
+
it "should return 60 for anything over 5" do
|
436
|
+
server.send(:wait_for, 6).should == 60
|
437
|
+
server.send(:wait_for, 1000).should == 60
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
427
441
|
end
|
428
442
|
end
|
429
443
|
|