+ 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
+ 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
+ # 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
+
+ test "test running job with just a few previous log records" do
+ job = api_fixture("jobs")['running']
+
+ # Create just one old log record
+ dispatch_log(owner_uuid: job['owner_uuid'],
+ object_uuid: job['uuid'],
+ event_type: "stderr",
+ properties: {"text" => "Historic log message"})
+
+ 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
+ assert_text 'Historic log message'
+
+ # Create new log record and expect it to show up in log tab
+ 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
+ max = 5
+ Rails.configuration.running_job_log_records_to_fetch = 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
+
+ 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..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
+ 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