workbench: Improve API server integration launch.
authorBrett Smith <brett@curoverse.com>
Fri, 21 Mar 2014 14:26:16 +0000 (10:26 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 21 Mar 2014 14:26:16 +0000 (10:26 -0400)
The previous version sometimes tried (and failed) to find the server
pid before rails wrote it.  This provides some limited retry, and
avoids spawning a subshell too.

apps/workbench/test/integration_helper.rb

index 5d06c22006844cc0be68db7a612eb25d2f67bf8d..5cd6f8421a25ad0db5c1e8954b8f7ccf08292b3c 100644 (file)
@@ -53,7 +53,12 @@ class IntegrationTestRunner < MiniTest::Unit
       _system('bundle', 'exec', 'rake', 'db:test:load')
       _system('bundle', 'exec', 'rake', 'db:fixtures:load')
       _system('bundle', 'exec', 'rails', 'server', '-d')
-      `cat tmp/pids/server.pid`.to_i
+      pid_path = 'tmp/pids/server.pid'
+      timeout = Time.now.tv_sec + 5
+      while (not File.exists? pid_path) and (Time.now.tv_sec < timeout)
+        sleep 0.2
+      end
+      IO.read(pid_path).to_i
     end
     begin
       super(args)