projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into 8465-stderr-redirection
[arvados.git]
/
services
/
api
/
test
/
integration
/
websocket_test.rb
diff --git
a/services/api/test/integration/websocket_test.rb
b/services/api/test/integration/websocket_test.rb
index 2f950a3ae21308570a6611f65cc4498420ce406c..549bbc6f9979d02c9f2f3bccd88cb7a078099c81 100644
(file)
--- a/
services/api/test/integration/websocket_test.rb
+++ b/
services/api/test/integration/websocket_test.rb
@@
-1,6
+1,6
@@
-require 'test_helper'
-require 'oj'
require 'database_cleaner'
require 'database_cleaner'
+require 'safe_json'
+require 'test_helper'
DatabaseCleaner.strategy = :deletion
DatabaseCleaner.strategy = :deletion
@@
-19,17
+19,20
@@
class WebsocketTest < ActionDispatch::IntegrationTest
s = TCPServer.new('0.0.0.0', 0)
@@port = s.addr[1]
s.close
s = TCPServer.new('0.0.0.0', 0)
@@port = s.addr[1]
s.close
- pidfile = "tmp/pids/passenger.#{@@port}.pid"
+
@@
pidfile = "tmp/pids/passenger.#{@@port}.pid"
DatabaseCleaner.start
Dir.chdir(Rails.root) do |apidir|
# Only passenger seems to be able to run the websockets server
# successfully.
DatabaseCleaner.start
Dir.chdir(Rails.root) do |apidir|
# Only passenger seems to be able to run the websockets server
# successfully.
- _system('passenger', 'start', '-d', "-p#{@@port}")
+ _system('passenger', 'start', '-d',
+ "-p#{@@port}",
+ "--log-file", "/dev/stderr",
+ "--pid-file", @@pidfile)
timeout = Time.now.tv_sec + 10
begin
sleep 0.2
begin
timeout = Time.now.tv_sec + 10
begin
sleep 0.2
begin
- server_pid = IO.read(pidfile).to_i
+ server_pid = IO.read(
@@
pidfile).to_i
good_pid = (server_pid > 0) and (Process.kill(0, pid) rescue false)
rescue Errno::ENOENT
good_pid = false
good_pid = (server_pid > 0) and (Process.kill(0, pid) rescue false)
rescue Errno::ENOENT
good_pid = false
@@
-44,7
+47,8
@@
class WebsocketTest < ActionDispatch::IntegrationTest
def self.shutdown
Dir.chdir(Rails.root) do
def self.shutdown
Dir.chdir(Rails.root) do
- _system('passenger', 'stop', "-p#{@@port}")
+ _system('passenger', 'stop', "-p#{@@port}",
+ "--pid-file", @@pidfile)
end
# DatabaseCleaner leaves the database empty. Prefer to leave it full.
dc = DatabaseController.new
end
# DatabaseCleaner leaves the database empty. Prefer to leave it full.
dc = DatabaseController.new
@@
-108,7
+112,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
ws_helper do |ws|
ws.on :message do |event|
ws_helper do |ws|
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
status = d["status"]
ws.close
end
status = d["status"]
ws.close
end
@@
-126,7
+130,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
status = d["status"]
ws.close
end
status = d["status"]
ws.close
end
@@
-148,7
+152,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-185,7
+189,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-225,7
+229,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-264,7
+268,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-308,7
+312,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-333,8
+337,6
@@
class WebsocketTest < ActionDispatch::IntegrationTest
test "connect, subscribe, ask events starting at seq num" do
state = 1
test "connect, subscribe, ask events starting at seq num" do
state = 1
- human = nil
- human_ev_uuid = nil
authorize_with :active
authorize_with :active
@@
-348,7
+350,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-373,12
+375,10
@@
class WebsocketTest < ActionDispatch::IntegrationTest
assert_equal expect_next_logs[1].object_uuid, l2
end
assert_equal expect_next_logs[1].object_uuid, l2
end
- test "connect, subscribe, get event, unsubscribe" do
- slow_test
+ slow_test "connect, subscribe, get event, unsubscribe" do
state = 1
spec = nil
spec_ev_uuid = nil
state = 1
spec = nil
spec_ev_uuid = nil
- filter_id = nil
authorize_with :active
authorize_with :active
@@
-394,7
+394,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-423,8
+423,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
assert_equal spec.uuid, spec_ev_uuid
end
assert_equal spec.uuid, spec_ev_uuid
end
- test "connect, subscribe, get event, unsubscribe with filter" do
- slow_test
+ slow_test "connect, subscribe, get event, unsubscribe with filter" do
state = 1
spec = nil
spec_ev_uuid = nil
state = 1
spec = nil
spec_ev_uuid = nil
@@
-443,7
+442,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-473,8
+472,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
end
- test "connect, subscribe, get event, try to unsubscribe with bogus filter" do
- slow_test
+ slow_test "connect, subscribe, get event, try to unsubscribe with bogus filter" do
state = 1
spec = nil
spec_ev_uuid = nil
state = 1
spec = nil
spec_ev_uuid = nil
@@
-489,7
+487,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-524,10
+522,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
assert_equal human.uuid, human_ev_uuid
end
assert_equal human.uuid, human_ev_uuid
end
-
-
- test "connected, not subscribed, no event" do
- slow_test
+ slow_test "connected, not subscribed, no event" do
authorize_with :active
ws_helper(token: :active, timeout: false) do |ws|
authorize_with :active
ws_helper(token: :active, timeout: false) do |ws|
@@
-547,8
+542,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
end
end
end
- test "connected, not authorized to see event" do
- slow_test
+ slow_test "connected, not authorized to see event" do
state = 1
authorize_with :admin
state = 1
authorize_with :admin
@@
-563,7
+557,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
case state
when 1
assert_equal 200, d["status"]
@@
-587,7
+581,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
status = d["status"]
ws.close
end
status = d["status"]
ws.close
end
@@
-605,7
+599,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
status = d["status"]
ws.close
end
status = d["status"]
ws.close
end
@@
-623,7
+617,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
status = d["status"]
ws.close
end
status = d["status"]
ws.close
end
@@
-646,7
+640,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when (1..Rails.configuration.websocket_max_filters)
assert_equal 200, d["status"]
case state
when (1..Rails.configuration.websocket_max_filters)
assert_equal 200, d["status"]
@@
-663,8
+657,7
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
end
- test "connect, subscribe, lots of events" do
- slow_test
+ slow_test "connect, subscribe, lots of events" do
state = 1
event_count = 0
log_start = Log.order(:id).last.id
state = 1
event_count = 0
log_start = Log.order(:id).last.id
@@
-682,13
+675,13
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
ActiveRecord::Base.transaction do
(1..202).each do
case state
when 1
assert_equal 200, d["status"]
ActiveRecord::Base.transaction do
(1..202).each do
-
spec =
Specimen.create
+ Specimen.create
end
end
state = 2
end
end
state = 2
@@
-709,8
+702,6
@@
class WebsocketTest < ActionDispatch::IntegrationTest
test "connect, subscribe with invalid filter" do
state = 1
test "connect, subscribe with invalid filter" do
state = 1
- human = nil
- human_ev_uuid = nil
authorize_with :active
authorize_with :active
@@
-721,12
+712,12
@@
class WebsocketTest < ActionDispatch::IntegrationTest
end
ws.on :message do |event|
end
ws.on :message do |event|
- d =
Oj.strict_
load event.data
+ d =
SafeJSON.
load event.data
case state
when 1
assert_equal 200, d["status"]
Specimen.create
case state
when 1
assert_equal 200, d["status"]
Specimen.create
-
human =
Human.create
+ Human.create
state = 2
when 2
assert_equal 500, d["status"]
state = 2
when 2
assert_equal 500, d["status"]