build_status_server 0.11 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- build_status_server (0.11)
4
+ build_status_server (0.12)
5
5
  json
6
6
 
7
7
  GEM
@@ -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 2 seconds and try again..."
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
@@ -1,3 +1,3 @@
1
1
  module BuildStatusServer
2
- VERSION = "0.11"
2
+ VERSION = "0.12"
3
3
  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).exactly(2).with("Will wait for 2 seconds and try again...")
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).twice.with(2)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build_status_server
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.11'
4
+ version: '0.12'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: