Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-04-28 13:27:48 +0300
committerJacob Vosmaer <jacob@gitlab.com>2017-04-28 13:27:48 +0300
commit106f3db9bb05244139ac530fcfe17c13b221d3aa (patch)
tree78d312e8bdde1ff90fcd7543733d89c96f9acebc /spec/unicorn
parentb325d4a658bd884d2d10b832032296e9e28bcc24 (diff)
Refactor timeout code
Diffstat (limited to 'spec/unicorn')
-rw-r--r--spec/unicorn/unicorn_spec.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/spec/unicorn/unicorn_spec.rb b/spec/unicorn/unicorn_spec.rb
index 30fc5562353..b473fa48392 100644
--- a/spec/unicorn/unicorn_spec.rb
+++ b/spec/unicorn/unicorn_spec.rb
@@ -39,14 +39,7 @@ describe 'Unicorn' do
cmd = %W[unicorn -E test -c #{config_path} #{Rails.root.join('config.ru')}]
@unicorn_master_pid = spawn(*cmd)
-
- 120.times do
- break if File.exist?(ready_file)
- pid = Process.waitpid(@unicorn_master_pid, Process::WNOHANG)
- raise "unicorn failed to boot: #{$?}" unless pid.nil?
-
- sleep 1
- end
+ wait_unicorn_boot!(@unicorn_master_pid, ready_file)
WebMock.allow_net_connect!
end
@@ -73,7 +66,23 @@ describe 'Unicorn' do
Process.kill('TERM', @unicorn_master_pid)
end
+ def wait_unicorn_boot!(master_pid, ready_file)
+ # Unicorn should boot in under 60 seconds so 120 seconds seems like a good timeout.
+ timeout = 120
+ timeout.times do
+ return if File.exist?(ready_file)
+ pid = Process.waitpid(master_pid, Process::WNOHANG)
+ raise "unicorn failed to boot: #{$?}" unless pid.nil?
+
+ sleep 1
+ end
+
+ raise "unicorn boot timed out after #{timeout} seconds"
+ end
+
def pid_gone?(pid)
+ # Worker termination should take less than a second. That makes 10
+ # seconds a generous timeout.
10.times do
begin
Process.kill(0, pid)