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
assert_text '1001 hello'
# Check that new value of scrollTop is greater than the old one
- assert page.evaluate_script("$('#event_log_div').scrollTop()") > old_top
+ 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)"
visit(page_with_token("admin", "/jobs/#{p.uuid}"))
assert_no_text 'complete'
- assert_no_text 'Re-run same version'
+ assert_no_text 'Re-run job'
p.state = "Complete"
p.save!
assert_text 'complete'
- assert_text 'Re-run same version'
+ assert_text 'Re-run job'
Thread.current[:arvados_api_token] = nil
end
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"
+
+ # Until graphable data arrives, we should see the text log but not the graph.
+ assert_selector '#event_log_div', visible: true
+ assert_no_selector '#log_graph_div', visible: true
+
+ 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}}})
+
+ # Log div should appear when the first data point arrives by websocket.
+ assert_selector '#log_graph_div', visible: true
+
+ # Using datapoint 1 instead of datapoint 0 because there will be a
+ # "dummy" datapoint with no actual stats 10 minutes previous to
+ # the one we're looking for, for the sake of making the x-axis of
+ # the graph show a full 10 minutes of time even though there is
+ # only a single real datapoint.
+ cpu_stat = page.evaluate_script("jobGraphData[1]['T1-cpu']")
+
+ 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,1.0,#{uuid}")
+ wait_for_ajax
+
+ # see above comment as to why we use datapoint 1 rather than 0
+ cpu_stat = page.evaluate_script("jobGraphData[1]['T1-cpu']")
+
+ assert_equal 45.3, (cpu_stat.to_f*100).round(1)
+ end
+
end