X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/22dbb0614da70ce16ec86d906ea222532b3b7c9f..f8e6cb30ca6a3cdb20be47f7a81663d4affd0b7f:/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 c8ffcfe0f6..648d59c690 100644 --- a/apps/workbench/test/integration/websockets_test.rb +++ b/apps/workbench/test/integration/websockets_test.rb @@ -1,20 +1,214 @@ require 'integration_helper' -require 'selenium-webdriver' -require 'headless' class WebsocketTest < ActionDispatch::IntegrationTest - setup do - headless = Headless.new - headless.start - Capybara.current_driver = :selenium + need_selenium "to make websockets work" end test "test page" do - visit(page_with_token("active", "/websockets")) + visit(page_with_token("admin", "/websockets")) fill_in("websocket-message-content", :with => "Stuff") click_button("Send") - assert page.has_text? '"status":400' + 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", 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 + + controller = c[0] + uuid = c[1] + + visit(page_with_token("admin", "/#{controller}/#{uuid}")) + click_link("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}}}) + 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"}}}) + assert_text '1001 hello' + + # Check that new value of scrollTop is greater than the old one + new_top = page.evaluate_script("$('#event_log_div').scrollTop()") + assert_operator new_top, :>, old_top + + # Now scroll to 30 pixels from the top + 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"}}}) + assert_text '1002 hello' + + # Check that we haven't changed scroll position + assert_equal 30, page.evaluate_script("$('#event_log_div').scrollTop()") + 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 + + test 'job graph appears when first data point arrives by websocket' do + use_token :admin do + Log.find(api_fixture('logs')['crunchstat_for_running_job']['uuid']).destroy + end + job_graph_first_datapoint_test expect_existing_datapoints: false + end + + def job_graph_first_datapoint_test expect_existing_datapoints: true + uuid = api_fixture('jobs')['running']['uuid'] + + visit page_with_token "active", "/jobs/#{uuid}" + click_link "Log" + + assert_selector '#event_log_div', visible: true + + if expect_existing_datapoints + assert_selector '#log_graph_div', visible: true + # Magic numbers 12.99 etc come from the job log fixture: + assert_last_datapoint 'T1-cpu', (((12.99+0.99)/10.0002)/8) + else + # Until graphable data arrives, we should see the text log but not the graph. + assert_no_selector '#log_graph_div', visible: true + end + + 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 + end + + # Graph should have appeared (even if it hadn't above). It's + # important not to wait like matchers usually do: we are + # confirming the graph is visible _immediately_ after the first + # data point arrives. + using_wait_time 0 do + assert_selector '#log_graph_div', visible: true + end + assert_last_datapoint 'T1-cpu', (((35.39+0.86)/10.0002)/8) + end + + test "live log charting from replayed log" do + uuid = api_fixture("jobs")['running']['uuid'] + + visit page_with_token "active", "/jobs/#{uuid}" + click_link "Log" + + assert_triggers_dom_event 'arv-log-event' do + ApiServerForTests.new.run_rake_task("replay_job_log", "test/job_logs/crunchstatshort.log,1.0,#{uuid}") + end + + assert_last_datapoint 'T1-cpu', (((35.39+0.86)/10.0002)/8) + end + + def assert_last_datapoint series, value + datum = page.evaluate_script("jobGraphData[jobGraphData.length-1]['#{series}']") + assert_in_epsilon value, datum.to_f + end end