4595: Merge branch 'master' into 4595-node-list-select
[arvados.git] / apps / workbench / test / test_helper.rb
index e3654877afe2c857829aafb2310909abbf5ae930..7f07f180db85340f07c7071c2bbe36433f44d4c1 100644 (file)
@@ -128,11 +128,6 @@ class ApiServerForTests
 
   def find_server_pid
     pid = nil
-    @pidfile = if @websocket
-                 WEBSOCKET_PID_PATH
-               else
-                 SERVER_PID_PATH
-               end
     begin
       pid = IO.read(@pidfile).to_i
       $stderr.puts "API server is running, pid #{pid.inspect}"
@@ -148,6 +143,12 @@ class ApiServerForTests
 
     @websocket = args.include?("--websockets")
 
+    @pidfile = if @websocket
+                 WEBSOCKET_PID_PATH
+               else
+                 SERVER_PID_PATH
+               end
+
     # Kill server left over from previous test run
     self.kill_server
 
@@ -156,13 +157,13 @@ class ApiServerForTests
       ENV["NO_COVERAGE_TEST"] = "1"
       if @websocket
         _system('bundle', 'exec', 'passenger', 'start', '-d', '-p3333',
-                '--pid-file', WEBSOCKET_PID_PATH)
+                '--pid-file', @pidfile)
       else
         make_ssl_cert
         _system('bundle', 'exec', 'rake', 'db:test:load')
         _system('bundle', 'exec', 'rake', 'db:fixtures:load')
         _system('bundle', 'exec', 'passenger', 'start', '-d', '-p3000',
-                '--pid-file', SERVER_PID_PATH,
+                '--pid-file', @pidfile,
                 '--ssl',
                 '--ssl-certificate', 'self-signed.pem',
                 '--ssl-certificate-key', 'self-signed.key')
@@ -181,6 +182,12 @@ class ApiServerForTests
       end
     end
   end
+
+  def run_rake_task(task_name, arg_string)
+    Dir.chdir(ARV_API_SERVER_DIR) do
+      _system('bundle', 'exec', 'rake', "#{task_name}[#{arg_string}]")
+    end
+  end
 end
 
 class ActionController::TestCase
@@ -203,6 +210,21 @@ class ActionController::TestCase
   end
 end
 
+# If it quacks like a duck, it must be a HTTP request object.
+class RequestDuck
+  def self.host
+    "localhost"
+  end
+
+  def self.port
+    8080
+  end
+
+  def self.protocol
+    "http"
+  end
+end
+
 if ENV["RAILS_ENV"].eql? 'test'
   ApiServerForTests.new.run
   ApiServerForTests.new.run ["--websockets"]