From 6e3b2cc860aff636460decd9e153dbb87f057065 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 19 Jul 2017 12:04:03 -0400 Subject: [PATCH] warmup prior to running tests --- lib/tasks/qunit.rake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/tasks/qunit.rake b/lib/tasks/qunit.rake index 9baf48a1af8..230022a2903 100644 --- a/lib/tasks/qunit.rake +++ b/lib/tasks/qunit.rake @@ -51,6 +51,25 @@ task "qunit:test", [:timeout] => :environment do |_, args| cmd += " #{args[:timeout]}" end + @now = Time.now + def elapsed + Time.now - @now + end + + # wait for server to accept connections + require 'net/http' + uri = URI("http://localhost:#{port}/assets/test_helper.js") + puts "Warming up Rails server" + begin + Net::HTTP.get(uri) + rescue Errno::ECONNREFUSED + sleep 1 + retry unless elapsed() > 60 + puts "Timed out. Can no connect to forked server!" + exit 1 + end + puts "Rails server is warmed up" + # wait for server to respond, will exception out on failure tries = 0 begin