X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e6d161cc976f253863c4b0788ce91c5955046972..f8991d36180bf9c2c261dee519b0c878306a35d5:/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 7211adbae4..7a8d7742f2 100644 --- a/apps/workbench/test/integration/websockets_test.rb +++ b/apps/workbench/test/integration/websockets_test.rb @@ -14,13 +14,13 @@ class WebsocketTest < ActionDispatch::IntegrationTest 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 page.has_no_text? '123 hello' + assert_no_text '123 hello' api = ArvadosApiClient.new @@ -29,56 +29,64 @@ class WebsocketTest < ActionDispatch::IntegrationTest object_uuid: "zzzzz-d1hrv-9fm8l10i9z2kqc6", event_type: "stderr", properties: {"text" => "123 hello"}}}) - assert page.has_text? '123 hello' + assert_text '123 hello' Thread.current[:arvados_api_token] = nil end - test "test live logging scrolling" do - visit(page_with_token("admin", "/pipeline_instances/zzzzz-d1hrv-9fm8l10i9z2kqc6")) - click_link("Log") - assert page.has_no_text? '123 hello' - api = ArvadosApiClient.new + [["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 - text = "" - (1..1000).each do |i| - text << "#{i} hello\n" - end + controller = c[0] + uuid = c[1] - Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] - api.api("logs", "", {log: { - object_uuid: "zzzzz-d1hrv-9fm8l10i9z2kqc6", - event_type: "stderr", - properties: {"text" => text}}}) - assert page.has_text? '1000 hello' + visit(page_with_token("admin", "/#{controller}/#{uuid}")) + click_link("Log") + assert_no_text '123 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("$('#pipeline_event_log_div').scrollTop()") + api = ArvadosApiClient.new - api.api("logs", "", {log: { - object_uuid: "zzzzz-d1hrv-9fm8l10i9z2kqc6", - event_type: "stderr", - properties: {"text" => "1001 hello\n"}}}) - assert page.has_text? '1001 hello' + text = "" + (1..1000).each do |i| + text << "#{i} hello\n" + end - # Check that new value of scrollTop is greater than the old one - assert page.evaluate_script("$('#pipeline_event_log_div').scrollTop()") > old_top + 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' - # Now scroll to 30 pixels from the top - page.execute_script "$('#pipeline_event_log_div').scrollTop(30)" - assert_equal 30, page.evaluate_script("$('#pipeline_event_log_div').scrollTop()") + # 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: "zzzzz-d1hrv-9fm8l10i9z2kqc6", - event_type: "stderr", - properties: {"text" => "1002 hello\n"}}}) - assert page.has_text? '1002 hello' + api.api("logs", "", {log: { + object_uuid: uuid, + event_type: "stderr", + properties: {"text" => "1001 hello\n"}}}) + assert_text '1001 hello' - # Check that we haven't changed scroll position - assert_equal 30, page.evaluate_script("$('#pipeline_event_log_div').scrollTop()") + # Check that new value of scrollTop is greater than the old one + assert page.evaluate_script("$('#event_log_div').scrollTop()") > old_top - Thread.current[:arvados_api_token] = nil + # 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()") + + Thread.current[:arvados_api_token] = nil + end end test "pipeline instance arv-refresh-on-log-event" do @@ -95,17 +103,17 @@ class WebsocketTest < ActionDispatch::IntegrationTest visit(page_with_token("admin", "/pipeline_instances/#{p.uuid}")) - assert page.has_text? 'Active' + assert_text 'Active' assert page.has_link? 'Pause' - assert page.has_no_text? 'Complete' + assert_no_text 'Complete' assert page.has_no_link? 'Re-run with latest' p.state = "Complete" p.save! - assert page.has_no_text? 'Active' + assert_no_text 'Active' assert page.has_no_link? 'Pause' - assert page.has_text? 'Complete' + assert_text 'Complete' assert page.has_link? 'Re-run with latest' Thread.current[:arvados_api_token] = nil @@ -118,14 +126,14 @@ class WebsocketTest < ActionDispatch::IntegrationTest visit(page_with_token("admin", "/jobs/#{p.uuid}")) - assert page.has_no_text? 'complete' - assert page.has_no_text? 'Re-run same version' + assert_no_text 'complete' + assert_no_text 'Re-run same version' p.state = "Complete" p.save! - assert page.has_text? 'complete' - assert page.has_text? 'Re-run same version' + assert_text 'complete' + assert_text 'Re-run same version' Thread.current[:arvados_api_token] = nil end @@ -135,7 +143,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest visit(page_with_token("admin", "/")) - assert page.has_no_text? 'test dashboard arv-refresh-on-log-event' + assert_no_text 'test dashboard arv-refresh-on-log-event' # Do something and check that the pane reloads. p = PipelineInstance.create({state: "RunningOnServer", @@ -144,9 +152,48 @@ class WebsocketTest < ActionDispatch::IntegrationTest } }) - assert page.has_text? 'test dashboard arv-refresh-on-log-event' + assert_text 'test dashboard arv-refresh-on-log-event' Thread.current[:arvados_api_token] = nil end + test "live log charting" do + uuid = api_fixture("jobs")['running']['uuid'] + + visit page_with_token "admin", "/jobs/#{uuid}" + click_link "Log" + + api = ArvadosApiClient.new + + # should give 45.3% or (((36.39+0.86)/10.0002)/8)*100 rounded to 1 decimal place + 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" + + Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token'] + api.api("logs", "", {log: { + object_uuid: uuid, + event_type: "stderr", + properties: {"text" => text}}}) + wait_for_ajax + + cpu_stat = page.evaluate_script("jobGraphData[0]['cpu-1']") + + assert_equal 45.3, (cpu_stat.to_f*100).round(1) + + Thread.current[:arvados_api_token] = nil + end + + test "live log charting from replayed log" do + uuid = api_fixture("jobs")['running']['uuid'] + + visit page_with_token "admin", "/jobs/#{uuid}" + click_link "Log" + + ApiServerForTests.new.run_rake_task("replay_job_log", "test/job_logs/crunchstatshort.log,#{uuid}") + wait_for_ajax + + cpu_stat = page.evaluate_script("jobGraphData[0]['cpu-1']") + + assert_equal 45.3, (cpu_stat.to_f*100).round(1) + end + end