X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e5ee153a56578d13a025cde47fd0c07e21fd975f..42c20b25e1325124b88e3b9b285544dc41122b56:/apps/workbench/test/integration/websockets_test.rb diff --git a/apps/workbench/test/integration/websockets_test.rb b/apps/workbench/test/integration/websockets_test.rb index 655ad92c94..83494173a9 100644 --- a/apps/workbench/test/integration/websockets_test.rb +++ b/apps/workbench/test/integration/websockets_test.rb @@ -1,66 +1,61 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'integration_helper' class WebsocketTest < ActionDispatch::IntegrationTest setup do need_selenium "to make websockets work" + @dispatch_client = ArvadosApiClient.new + end + + def dispatch_log(body) + use_token :dispatch1 do + @dispatch_client.api('logs', '', log: body) + end end test "test page" do - visit(page_with_token("admin", "/websockets")) + visit(page_with_token("active", "/websockets")) fill_in("websocket-message-content", :with => "Stuff") click_button("Send") assert_text '"status":400' end - test "test live logging" do - visit(page_with_token("admin", "/pipeline_instances/zzzzz-d1hrv-9fm8l10i9z2kqc6")) - click_link("Log") - assert_no_text '123 hello' - - api = ArvadosApiClient.new - - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - api.api("logs", "", {log: { - object_uuid: "zzzzz-d1hrv-9fm8l10i9z2kqc6", - event_type: "stderr", - properties: {"text" => "123 hello"}}}) - assert_text '123 hello' - end - + [ + ['pipeline_instances', 'pipeline_in_running_state', api_fixture('jobs')['running']], + ['jobs', 'running'], + ['containers', 'running'], + ['container_requests', 'running', api_fixture('containers')['running']], + ].each do |controller, view_fixture_name, log_target_fixture| + view_fixture = api_fixture(controller)[view_fixture_name] + log_target_fixture ||= view_fixture - [["pipeline_instances", api_fixture("pipeline_instances")['pipeline_with_newer_template']['uuid']], - ["jobs", api_fixture("jobs")['running']['uuid']]].each do |c| - test "test live logging scrolling #{c[0]}" do + test "test live logging and scrolling for #{controller}" do - controller = c[0] - uuid = c[1] - - visit(page_with_token("admin", "/#{controller}/#{uuid}")) - click_link("Log") + visit(page_with_token("active", "/#{controller}/#{view_fixture['uuid']}\#Log")) assert_no_text '123 hello' - api = ArvadosApiClient.new - text = "" (1..1000).each do |i| text << "#{i} hello\n" end - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - api.api("logs", "", {log: { - object_uuid: uuid, - event_type: "stderr", - properties: {"text" => text}}}) + dispatch_log(owner_uuid: log_target_fixture['owner_uuid'], + object_uuid: log_target_fixture['uuid'], + event_type: "stderr", + properties: {"text" => text}) assert_text '1000 hello' # First test that when we're already at the bottom of the page, it scrolls down # when a new line is added. old_top = page.evaluate_script("$('#event_log_div').scrollTop()") - api.api("logs", "", {log: { - object_uuid: uuid, - event_type: "stderr", - properties: {"text" => "1001 hello\n"}}}) + dispatch_log(owner_uuid: log_target_fixture['owner_uuid'], + object_uuid: log_target_fixture['uuid'], + event_type: "dispatch", + properties: {"text" => "1001 hello\n"}) assert_text '1001 hello' # Check that new value of scrollTop is greater than the old one @@ -71,10 +66,10 @@ class WebsocketTest < ActionDispatch::IntegrationTest page.execute_script "$('#event_log_div').scrollTop(30)" assert_equal 30, page.evaluate_script("$('#event_log_div').scrollTop()") - api.api("logs", "", {log: { - object_uuid: uuid, - event_type: "stderr", - properties: {"text" => "1002 hello\n"}}}) + dispatch_log(owner_uuid: log_target_fixture['owner_uuid'], + object_uuid: log_target_fixture['uuid'], + event_type: "stdout", + properties: {"text" => "1002 hello\n"}) assert_text '1002 hello' # Check that we haven't changed scroll position @@ -82,68 +77,6 @@ class WebsocketTest < ActionDispatch::IntegrationTest end end - test "pipeline instance arv-refresh-on-log-event" do - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - # Do something and check that the pane reloads. - p = PipelineInstance.create({state: "RunningOnServer", - components: { - c1: { - script: "test_hash.py", - script_version: "1de84a854e2b440dc53bf42f8548afa4c17da332" - } - } - }) - - visit(page_with_token("admin", "/pipeline_instances/#{p.uuid}")) - - assert_text 'Active' - assert page.has_link? 'Pause' - assert_no_text 'Complete' - assert page.has_no_link? 'Re-run with latest' - - p.state = "Complete" - p.save! - - assert_no_text 'Active' - assert page.has_no_link? 'Pause' - assert_text 'Complete' - assert page.has_link? 'Re-run with latest' - end - - test "job arv-refresh-on-log-event" do - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - # Do something and check that the pane reloads. - p = Job.where(uuid: api_fixture('jobs')['running_will_be_completed']['uuid']).results.first - - visit(page_with_token("admin", "/jobs/#{p.uuid}")) - - assert_no_text 'complete' - assert_no_text 'Re-run job' - - p.state = "Complete" - p.save! - - assert_text 'complete' - assert_text 'Re-run job' - end - - test "dashboard arv-refresh-on-log-event" do - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - - visit(page_with_token("admin", "/")) - - assert_no_text 'test dashboard arv-refresh-on-log-event' - - # Do something and check that the pane reloads. - p = PipelineInstance.create({state: "RunningOnServer", - name: "test dashboard arv-refresh-on-log-event", - components: { - } - }) - - assert_text 'test dashboard arv-refresh-on-log-event' - end - test 'job graph appears when first data point is already in logs table' do job_graph_first_datapoint_test end @@ -175,13 +108,10 @@ class WebsocketTest < ActionDispatch::IntegrationTest text = "2014-11-07_23:33:51 #{uuid} 31708 1 stderr crunchstat: cpu 1970.8200 user 60.2700 sys 8 cpus -- interval 10.0002 seconds 35.3900 user 0.8600 sys" assert_triggers_dom_event 'arv-log-event' do - use_token :active do - api = ArvadosApiClient.new - api.api("logs", "", {log: { - object_uuid: uuid, - event_type: "stderr", - properties: {"text" => text}}}) - end + dispatch_log(owner_uuid: api_fixture('jobs')['running']['owner_uuid'], + object_uuid: uuid, + event_type: "stderr", + properties: {"text" => text}) end # Graph should have appeared (even if it hadn't above). It's @@ -213,65 +143,56 @@ class WebsocketTest < ActionDispatch::IntegrationTest end test "test running job with just a few previous log records" do - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - job = Job.where(uuid: api_fixture("jobs")['running']['uuid']).results.first - visit page_with_token("admin", "/jobs/#{job.uuid}") - - api = ArvadosApiClient.new + job = api_fixture("jobs")['running'] # Create just one old log record - api.api("logs", "", {log: { - object_uuid: job.uuid, - event_type: "stderr", - properties: {"text" => "Historic log message"}}}) + dispatch_log(owner_uuid: job['owner_uuid'], + object_uuid: job['uuid'], + event_type: "stderr", + properties: {"text" => "Historic log message"}) - click_link("Log") + visit page_with_token("active", "/jobs/#{job['uuid']}\#Log") # Expect "all" historic log records because we have less than - # default Rails.configuration.running_job_log_records_to_fetch count + # default Rails.configuration.Workbench.RunningJobLogRecordsToFetch assert_text 'Historic log message' # Create new log record and expect it to show up in log tab - api.api("logs", "", {log: { - object_uuid: job.uuid, - event_type: "stderr", - properties: {"text" => "Log message after subscription"}}}) + dispatch_log(owner_uuid: job['owner_uuid'], + object_uuid: job['uuid'], + event_type: "stderr", + properties: {"text" => "Log message after subscription"}) assert_text 'Log message after subscription' end test "test running job with too many previous log records" do - Rails.configuration.running_job_log_records_to_fetch = 5 - - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - job = Job.where(uuid: api_fixture("jobs")['running']['uuid']).results.first - - visit page_with_token("admin", "/jobs/#{job.uuid}") - - api = ArvadosApiClient.new - - # Create Rails.configuration.running_job_log_records_to_fetch + 1 log records - (0..Rails.configuration.running_job_log_records_to_fetch).each do |count| - api.api("logs", "", {log: { - object_uuid: job.uuid, - event_type: "stderr", - properties: {"text" => "Old log message #{count}"}}}) + max = 5 + Rails.configuration.Workbench.RunningJobLogRecordsToFetch = max + job = api_fixture("jobs")['running'] + + # Create max+1 log records + (0..max).each do |count| + dispatch_log(owner_uuid: job['owner_uuid'], + object_uuid: job['uuid'], + event_type: "stderr", + properties: {"text" => "Old log message #{count}"}) end - # Go to log tab, which results in subscribing to websockets - click_link("Log") + visit page_with_token("active", "/jobs/#{job['uuid']}\#Log") # Expect all but the first historic log records, # because that was one too many than fetch count. - (1..Rails.configuration.running_job_log_records_to_fetch).each do |count| + (1..max).each do |count| assert_text "Old log message #{count}" end assert_no_text 'Old log message 0' # Create one more log record after subscription - api.api("logs", "", {log: { - object_uuid: job.uuid, - event_type: "stderr", - properties: {"text" => "Life goes on!"}}}) + dispatch_log(owner_uuid: job['owner_uuid'], + object_uuid: job['uuid'], + event_type: "stderr", + properties: {"text" => "Life goes on!"}) + # Expect it to show up in log tab assert_text 'Life goes on!' end