[ARVADOS] updated: f0ca76acaa3a4e3713f7aef6a6bb778e6e71e562

git at public.curoverse.com git at public.curoverse.com
Thu Apr 24 11:32:48 EDT 2014


Summary of changes:
 services/api/config/initializers/eventbus.rb    |    2 +-
 services/api/test/integration/websocket_test.rb |   25 +++++++++++++
 services/api/test/websocket_runner.rb           |   42 +++++++++++++++++++++++
 3 files changed, 68 insertions(+), 1 deletions(-)
 create mode 100644 services/api/test/integration/websocket_test.rb
 create mode 100644 services/api/test/websocket_runner.rb

       via  f0ca76acaa3a4e3713f7aef6a6bb778e6e71e562 (commit)
      from  1f9df3c7140d4eacf58d4e19a7ddc81260296229 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit f0ca76acaa3a4e3713f7aef6a6bb778e6e71e562
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Apr 24 11:32:42 2014 -0400

    Added test runner for websocket tests.  Requires passenger standalone to be
    installed.

diff --git a/services/api/config/initializers/eventbus.rb b/services/api/config/initializers/eventbus.rb
index 2d2b7bc..2902403 100644
--- a/services/api/config/initializers/eventbus.rb
+++ b/services/api/config/initializers/eventbus.rb
@@ -1,7 +1,7 @@
 require 'eventbus'
 
 Server::Application.configure do
-  if ENV['ARVADOS_WEBSOCKETS']
+  if ENV['ARVADOS_WEBSOCKETS'] == '1'
     config.middleware.insert_after ArvadosApiToken, RackSocket, {:handler => EventBus, :websocket_only => true }
   end
 end
diff --git a/services/api/test/integration/websocket_test.rb b/services/api/test/integration/websocket_test.rb
new file mode 100644
index 0000000..ed82fe0
--- /dev/null
+++ b/services/api/test/integration/websocket_test.rb
@@ -0,0 +1,25 @@
+require 'test_helper'
+require 'websocket_runner'
+
+class WebsocketTest < ActionDispatch::IntegrationTest
+
+  test "just connect" do
+    opened = false
+    EM.run {
+      ws = Faye::WebSocket::Client.new('ws://localhost:3002/websocket')
+
+      ws.on :open do |event|
+        opened = true
+        ws.close
+      end
+
+      ws.on :close do |event|
+        p [:close, event.code, event.reason]
+        EM.stop_event_loop
+      end
+    }
+
+    assert opened, "Should have opened web socket"
+  end
+
+end
diff --git a/services/api/test/websocket_runner.rb b/services/api/test/websocket_runner.rb
new file mode 100644
index 0000000..2d6f245
--- /dev/null
+++ b/services/api/test/websocket_runner.rb
@@ -0,0 +1,42 @@
+require 'bundler'
+
+$ARV_API_SERVER_DIR = File.expand_path('../..', __FILE__)
+SERVER_PID_PATH = 'tmp/pids/passenger.3002.pid'
+
+class WebsocketTestRunner < MiniTest::Unit
+  def _system(*cmd)
+    Bundler.with_clean_env do
+      if not system({'ARVADOS_WEBSOCKETS' => '1'}, *cmd)
+        raise RuntimeError, "#{cmd[0]} returned exit code #{$?.exitstatus}"
+      end
+    end
+  end
+
+  def _run(args=[])
+    server_pid = Dir.chdir($ARV_API_SERVER_DIR) do |apidir|
+      # Only passenger seems to be able to run the websockets server successfully.
+      _system('passenger', 'start', '-d', '-p3002')
+      timeout = Time.now.tv_sec + 10
+      begin
+        sleep 0.2
+        begin
+          server_pid = IO.read(SERVER_PID_PATH).to_i
+          good_pid = (server_pid > 0) and (Process.kill(0, pid) rescue false)
+        rescue Errno::ENOENT
+          good_pid = false
+        end
+      end while (not good_pid) and (Time.now.tv_sec < timeout)
+      if not good_pid
+        raise RuntimeError, "could not find API server Rails pid"
+      end
+      server_pid
+    end
+    begin
+      super(args)
+    ensure
+      Process.kill('TERM', server_pid)
+    end
+  end
+end
+
+MiniTest::Unit.runner = WebsocketTestRunner.new

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list