DEV: add "WAIT_FOR_URL" env to smoke test

DEV: add “WAIT_FOR_URL” env to smoke test

This allows you to wait up to N seconds for the smoke test url to come up in some cases you want to kick off the smoke test prior to having the smoke test env ready to accept connections

diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rake
index d8eefa9..57630f6 100644
--- a/lib/tasks/smoke_test.rake
+++ b/lib/tasks/smoke_test.rake
@@ -33,12 +33,31 @@ task "smoke:test" do
   dir = ENV["SMOKE_TEST_SCREENSHOT_PATH"] || 'tmp/smoke-test-screenshots'
   FileUtils.mkdir_p(dir) unless Dir.exists?(dir)
 
-  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
-    http.request(request)
+  wait = ENV["WAIT_FOR_URL"].to_i
+
+  success = false
+  code = nil
+  retries = 0
+
+  loop do
+    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
+      http.request(request)
+    end
+
+    success = response.code == "200"
+    code = response.code
+
+    if !success && wait > 0
+      sleep 5
+      wait -= 5
+      retries += 1
+    else
+      break
+    end
   end
 
-  if response.code != "200"
-    raise "TRIVIAL GET FAILED WITH #{response.code}"
+  if !success
+    raise "TRIVIAL GET FAILED WITH #{code}: retried #{retries} times"
   end
 
   results = +""
diff --git a/test/smoke_test.js b/test/smoke_test.js
index 5756332..31f61ab 100644
--- a/test/smoke_test.js
+++ b/test/smoke_test.js
@@ -1,3 +1,5 @@
+/*eslint no-console: "off"*/
+
 const args = process.argv.slice(2);
 
 if (args.length < 1 || args.length > 2) {

GitHub sha: 50e6ee55

1 Like