closes #9684
[arvados.git] / apps / workbench / test / integration / websockets_test.rb
index 648d59c69000b19cfca089d4aac154da5e2529c7..e9f5a799c0d5444ed453381aa063002fd0e74b9c 100644 (file)
@@ -27,13 +27,17 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     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|
+  [
+   ["pipeline_instances", api_fixture("pipeline_instances")['pipeline_with_newer_template']['uuid']],
+   ["jobs", api_fixture("jobs")['running']['uuid']],
+   ["containers", api_fixture("containers")['running']['uuid']],
+   ["container_requests", api_fixture("container_requests")['running']['uuid'], api_fixture("containers")['running']['uuid']],
+  ].each do |c|
     test "test live logging scrolling #{c[0]}" do
 
       controller = c[0]
       uuid = c[1]
+      log_uuid = c[2] || c[1]
 
       visit(page_with_token("admin", "/#{controller}/#{uuid}"))
       click_link("Log")
@@ -48,7 +52,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
 
       Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
       api.api("logs", "", {log: {
-                  object_uuid: uuid,
+                  object_uuid: log_uuid,
                   event_type: "stderr",
                   properties: {"text" => text}}})
       assert_text '1000 hello'
@@ -58,7 +62,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
       old_top = page.evaluate_script("$('#event_log_div').scrollTop()")
 
       api.api("logs", "", {log: {
-                  object_uuid: uuid,
+                  object_uuid: log_uuid,
                   event_type: "stderr",
                   properties: {"text" => "1001 hello\n"}}})
       assert_text '1001 hello'
@@ -72,7 +76,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
       assert_equal 30, page.evaluate_script("$('#event_log_div').scrollTop()")
 
       api.api("logs", "", {log: {
-                  object_uuid: uuid,
+                  object_uuid: log_uuid,
                   event_type: "stderr",
                   properties: {"text" => "1002 hello\n"}}})
       assert_text '1002 hello'
@@ -211,4 +215,68 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     datum = page.evaluate_script("jobGraphData[jobGraphData.length-1]['#{series}']")
     assert_in_epsilon value, datum.to_f
   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
+
+    # Create just one old log record
+    api.api("logs", "", {log: {
+                object_uuid: job.uuid,
+                event_type: "stderr",
+                properties: {"text" => "Historic log message"}}})
+
+    click_link("Log")
+
+    # Expect "all" historic log records because we have less than
+    # default Rails.configuration.running_job_log_records_to_fetch count
+    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"}}})
+    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}"}}})
+    end
+
+    # Go to log tab, which results in subscribing to websockets
+    click_link("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|
+      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!"}}})
+    # Expect it to show up in log tab
+    assert_text 'Life goes on!'
+  end
 end