1 require 'integration_helper'
3 class WebsocketTest < ActionDispatch::IntegrationTest
5 need_selenium "to make websockets work"
9 visit(page_with_token("admin", "/websockets"))
10 fill_in("websocket-message-content", :with => "Stuff")
12 assert_text '"status":400'
15 test "test live logging" do
16 visit(page_with_token("admin", "/pipeline_instances/zzzzz-d1hrv-9fm8l10i9z2kqc6"))
18 assert_no_text '123 hello'
20 api = ArvadosApiClient.new
22 Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
23 api.api("logs", "", {log: {
24 object_uuid: "zzzzz-d1hrv-9fm8l10i9z2kqc6",
26 properties: {"text" => "123 hello"}}})
27 assert_text '123 hello'
28 Thread.current[:arvados_api_token] = nil
32 [["pipeline_instances", api_fixture("pipeline_instances")['pipeline_with_newer_template']['uuid']],
33 ["jobs", api_fixture("jobs")['running']['uuid']]].each do |c|
34 test "test live logging scrolling #{c[0]}" do
39 visit(page_with_token("admin", "/#{controller}/#{uuid}"))
41 assert_no_text '123 hello'
43 api = ArvadosApiClient.new
47 text << "#{i} hello\n"
50 Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
51 api.api("logs", "", {log: {
54 properties: {"text" => text}}})
55 assert_text '1000 hello'
57 # First test that when we're already at the bottom of the page, it scrolls down
58 # when a new line is added.
59 old_top = page.evaluate_script("$('#event_log_div').scrollTop()")
61 api.api("logs", "", {log: {
64 properties: {"text" => "1001 hello\n"}}})
65 assert_text '1001 hello'
67 # Check that new value of scrollTop is greater than the old one
68 assert page.evaluate_script("$('#event_log_div').scrollTop()") > old_top
70 # Now scroll to 30 pixels from the top
71 page.execute_script "$('#event_log_div').scrollTop(30)"
72 assert_equal 30, page.evaluate_script("$('#event_log_div').scrollTop()")
74 api.api("logs", "", {log: {
77 properties: {"text" => "1002 hello\n"}}})
78 assert_text '1002 hello'
80 # Check that we haven't changed scroll position
81 assert_equal 30, page.evaluate_script("$('#event_log_div').scrollTop()")
83 Thread.current[:arvados_api_token] = nil
87 test "pipeline instance arv-refresh-on-log-event" do
88 Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
89 # Do something and check that the pane reloads.
90 p = PipelineInstance.create({state: "RunningOnServer",
93 script: "test_hash.py",
94 script_version: "1de84a854e2b440dc53bf42f8548afa4c17da332"
99 visit(page_with_token("admin", "/pipeline_instances/#{p.uuid}"))
102 assert page.has_link? 'Pause'
103 assert_no_text 'Complete'
104 assert page.has_no_link? 'Re-run with latest'
109 assert_no_text 'Active'
110 assert page.has_no_link? 'Pause'
111 assert_text 'Complete'
112 assert page.has_link? 'Re-run with latest'
114 Thread.current[:arvados_api_token] = nil
117 test "job arv-refresh-on-log-event" do
118 Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
119 # Do something and check that the pane reloads.
120 p = Job.where(uuid: api_fixture('jobs')['running_will_be_completed']['uuid']).results.first
122 visit(page_with_token("admin", "/jobs/#{p.uuid}"))
124 assert_no_text 'complete'
125 assert_no_text 'Re-run job'
130 assert_text 'complete'
131 assert_text 'Re-run job'
133 Thread.current[:arvados_api_token] = nil
136 test "dashboard arv-refresh-on-log-event" do
137 Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
139 visit(page_with_token("admin", "/"))
141 assert_no_text 'test dashboard arv-refresh-on-log-event'
143 # Do something and check that the pane reloads.
144 p = PipelineInstance.create({state: "RunningOnServer",
145 name: "test dashboard arv-refresh-on-log-event",
150 assert_text 'test dashboard arv-refresh-on-log-event'
152 Thread.current[:arvados_api_token] = nil
155 test "live log charting" do
156 uuid = api_fixture("jobs")['running']['uuid']
158 visit page_with_token "admin", "/jobs/#{uuid}"
161 api = ArvadosApiClient.new
163 # should give 45.3% or (((36.39+0.86)/10.0002)/8)*100 rounded to 1 decimal place
164 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"
166 Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
167 api.api("logs", "", {log: {
169 event_type: "stderr",
170 properties: {"text" => text}}})
173 # 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
174 cpu_stat = page.evaluate_script("jobGraphData[1]['T1-cpu']")
176 assert_equal 45.3, (cpu_stat.to_f*100).round(1)
178 Thread.current[:arvados_api_token] = nil
181 test "live log charting from replayed log" do
182 uuid = api_fixture("jobs")['running']['uuid']
184 visit page_with_token "admin", "/jobs/#{uuid}"
187 ApiServerForTests.new.run_rake_task("replay_job_log", "test/job_logs/crunchstatshort.log,1.0,#{uuid}")
190 # see above comment as to why we use datapoint 1 rather than 0
191 cpu_stat = page.evaluate_script("jobGraphData[1]['T1-cpu']")
193 assert_equal 45.3, (cpu_stat.to_f*100).round(1)