[ARVADOS] updated: b046d1f162990361418a8e926aead5b307402a42
Git user
git at public.curoverse.com
Tue Sep 6 10:14:20 EDT 2016
Summary of changes:
apps/workbench/app/assets/javascripts/work_unit_log.js | 2 +-
apps/workbench/test/integration/work_units_test.rb | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
discards 50dc789ab65ad6edc6a32154f2426da640b2d265 (commit)
via b046d1f162990361418a8e926aead5b307402a42 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (50dc789ab65ad6edc6a32154f2426da640b2d265)
\
N -- N -- N (b046d1f162990361418a8e926aead5b307402a42)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit b046d1f162990361418a8e926aead5b307402a42
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Sep 6 10:11:25 2016 -0400
9679: Mention container state changes in container [request] log messages.
diff --git a/apps/workbench/app/assets/javascripts/work_unit_log.js b/apps/workbench/app/assets/javascripts/work_unit_log.js
index 0760692..07ca74c 100644
--- a/apps/workbench/app/assets/javascripts/work_unit_log.js
+++ b/apps/workbench/app/assets/javascripts/work_unit_log.js
@@ -1,18 +1,63 @@
$(document).on('arv-log-event', '.arv-log-event-handler-append-logs', function(event, eventData){
+ var wasatbottom, txt;
if (this != event.target) {
// Not interested in events sent to child nodes.
return;
}
- var wasatbottom = ($(this).scrollTop() + $(this).height() >= this.scrollHeight);
- if (eventData.properties != null && eventData.properties.text != null) {
- if( eventData.prepend ) {
- $(this).prepend(eventData.properties.text);
- } else {
- $(this).append(eventData.properties.text);
+ if (!('properties' in eventData)) {
+ return;
+ }
+
+ txt = '';
+ if ('text' in eventData.properties) {
+ txt += eventData.properties.text;
+ }
+ if (eventData.event_type == 'update' &&
+ eventData.object_uuid.indexOf("-dz642-") == 5 &&
+ 'old_attributes' in eventData.properties &&
+ 'new_attributes' in eventData.properties) {
+ // Container update
+ if (eventData.properties.old_attributes.state != eventData.properties.new_attributes.state) {
+ var stamp = eventData.event_at + " ";
+ switch(eventData.properties.new_attributes.state) {
+ case "Queued":
+ txt += stamp + "Container "+eventData.object_uuid+" was returned to the queue\n";
+ break;
+ case "Locked":
+ txt += stamp + "Container "+eventData.object_uuid+" was taken from the queue by a dispatch process\n";
+ break;
+ case "Running":
+ txt += stamp + "Container "+eventData.object_uuid+" started\n";
+ break;
+ case "Complete":
+ var outcome = eventData.properties.new_attributes.exit_code === 0 ? "success" : "failure";
+ txt += stamp + "Container "+eventData.object_uuid+" finished with exit code " +
+ eventData.properties.new_attributes.exit_code +
+ " ("+outcome+")\n";
+ break;
+ case "Cancelled":
+ txt += stamp + "Container "+eventData.object_uuid+" was cancelled\n";
+ break;
+ default:
+ // Unknown state -- unexpected, might as well log it.
+ txt += stamp + "Container "+eventData.object_uuid+" changed state to " +
+ eventData.properties.new_attributes.state + "\n";
+ break;
+ }
}
}
+ if (txt == '') {
+ return;
+ }
+
+ wasatbottom = ($(this).scrollTop() + $(this).height() >= this.scrollHeight);
+ if (eventData.prepend) {
+ $(this).prepend(txt);
+ } else {
+ $(this).append(txt);
+ }
if (wasatbottom) {
this.scrollTop = this.scrollHeight;
}
diff --git a/apps/workbench/app/models/container_work_unit.rb b/apps/workbench/app/models/container_work_unit.rb
index 2580105..be526ca 100644
--- a/apps/workbench/app/models/container_work_unit.rb
+++ b/apps/workbench/app/models/container_work_unit.rb
@@ -131,7 +131,7 @@ class ContainerWorkUnit < ProxyWorkUnit
end
def log_object_uuids
- [get_combined(:uuid), get(:uuid)].uniq
+ [get(:uuid, @container), get(:uuid, @proxied)].compact
end
def render_log
diff --git a/apps/workbench/test/helpers/fake_websocket_helper.rb b/apps/workbench/test/helpers/fake_websocket_helper.rb
new file mode 100644
index 0000000..91d2575
--- /dev/null
+++ b/apps/workbench/test/helpers/fake_websocket_helper.rb
@@ -0,0 +1,18 @@
+module FakeWebsocketHelper
+ def use_fake_websocket_driver
+ Capybara.current_driver = :poltergeist_with_fake_websocket
+ end
+
+ def fake_websocket_event(logdata)
+ stamp = Time.now.utc.in_time_zone.as_json
+ defaults = {
+ owner_uuid: api_fixture('users')['system_user']['uuid'],
+ event_at: stamp,
+ created_at: stamp,
+ updated_at: stamp,
+ }
+ event = {data: Oj.dump(defaults.merge(logdata), mode: :compat)}
+ script = '$(window).data("arv-websocket").onmessage('+Oj.dump(event, mode: :compat)+');'
+ page.evaluate_script(script)
+ end
+end
diff --git a/apps/workbench/test/integration/work_units_test.rb b/apps/workbench/test/integration/work_units_test.rb
index 7d19fcc..eded53e 100644
--- a/apps/workbench/test/integration/work_units_test.rb
+++ b/apps/workbench/test/integration/work_units_test.rb
@@ -1,6 +1,9 @@
+require 'helpers/fake_websocket_helper'
require 'integration_helper'
class WorkUnitsTest < ActionDispatch::IntegrationTest
+ include FakeWebsocketHelper
+
setup do
need_javascript
end
@@ -128,4 +131,78 @@ class WorkUnitsTest < ActionDispatch::IntegrationTest
assert_selector 'a', text: template_name
end
end
+
+ test 'display container state changes in Container Request live log' do
+ use_fake_websocket_driver
+ c = api_fixture('containers')['queued']
+ cr = api_fixture('container_requests')['queued']
+ visit page_with_token('active', '/container_requests/'+cr['uuid'])
+ click_link('Log')
+
+ # The attrs of the "terminal window" text div in the log tab
+ # indicates which objects' events are worth displaying. Events
+ # that arrive too early (before that div exists) are not
+ # shown. For the user's sake, these early logs should also be
+ # retrieved and shown one way or another -- but in this particular
+ # test, we are only interested in logs that arrive by
+ # websocket. Therefore, to avoid races, we wait for the log tab to
+ # display before sending any events.
+ assert_text 'Recent logs'
+
+ [[{
+ event_type: 'dispatch',
+ properties: {
+ text: "dispatch logged a fake message\n",
+ },
+ }, "dispatch logged"],
+ [{
+ event_type: 'update',
+ properties: {
+ old_attributes: {state: 'Locked'},
+ new_attributes: {state: 'Queued'},
+ },
+ }, "Container #{c['uuid']} was returned to the queue"],
+ [{
+ event_type: 'update',
+ properties: {
+ old_attributes: {state: 'Queued'},
+ new_attributes: {state: 'Locked'},
+ },
+ }, "Container #{c['uuid']} was taken from the queue by a dispatch process"],
+ [{
+ event_type: 'crunch-run',
+ properties: {
+ text: "according to fake crunch-run,\nsome setup stuff happened on the compute node\n",
+ },
+ }, "setup stuff happened"],
+ [{
+ event_type: 'update',
+ properties: {
+ old_attributes: {state: 'Locked'},
+ new_attributes: {state: 'Running'},
+ },
+ }, "Container #{c['uuid']} started"],
+ [{
+ event_type: 'update',
+ properties: {
+ old_attributes: {state: 'Running'},
+ new_attributes: {state: 'Complete', exit_code: 1},
+ },
+ }, "Container #{c['uuid']} finished with exit code 1 (failure)"],
+ # It's unrealistic for state to change again once it's Complete,
+ # but the logging code doesn't care, so we do it to keep the test
+ # simple.
+ [{
+ event_type: 'update',
+ properties: {
+ old_attributes: {state: 'Running'},
+ new_attributes: {state: 'Cancelled'},
+ },
+ }, "Container #{c['uuid']} was cancelled"],
+ ].each do |send_event, expect_log_text|
+ assert_no_text(expect_log_text)
+ fake_websocket_event(send_event.merge(object_uuid: c['uuid']))
+ assert_text(expect_log_text)
+ end
+ end
end
diff --git a/apps/workbench/test/integration_helper.rb b/apps/workbench/test/integration_helper.rb
index c94fc61..f0c811a 100644
--- a/apps/workbench/test/integration_helper.rb
+++ b/apps/workbench/test/integration_helper.rb
@@ -44,6 +44,11 @@ Capybara.register_driver :poltergeist_debug do |app|
Capybara::Poltergeist::Driver.new app, poltergeist_opts.merge(inspector: true)
end
+Capybara.register_driver :poltergeist_with_fake_websocket do |app|
+ js = File.expand_path '../support/fake_websocket.js', __FILE__
+ Capybara::Poltergeist::Driver.new app, poltergeist_opts.merge(extensions: [js])
+end
+
Capybara.register_driver :poltergeist_without_file_api do |app|
js = File.expand_path '../support/remove_file_api.js', __FILE__
Capybara::Poltergeist::Driver.new app, poltergeist_opts.merge(extensions: [js])
diff --git a/apps/workbench/test/support/fake_websocket.js b/apps/workbench/test/support/fake_websocket.js
new file mode 100644
index 0000000..b10f10f
--- /dev/null
+++ b/apps/workbench/test/support/fake_websocket.js
@@ -0,0 +1,15 @@
+sockets = [];
+window.WebSocket = function(url) {
+ sockets.push(this);
+ window.setTimeout(function() {
+ sockets.map(function(s) {
+ s.onopen();
+ });
+ sockets.splice(0);
+ }, 1);
+}
+
+window.WebSocket.prototype.send = function(msg) {
+ // Uncomment for debugging:
+ // console.log("fake WebSocket: send: "+msg);
+}
diff --git a/apps/workbench/test/test_helper.rb b/apps/workbench/test/test_helper.rb
index b8aa82e..72b5a89 100644
--- a/apps/workbench/test/test_helper.rb
+++ b/apps/workbench/test/test_helper.rb
@@ -83,7 +83,7 @@ module ApiFixtureLoader
file = file[0, trim_index] if trim_index
YAML.load(file)
end
- keys.inject(@@api_fixtures[name]) { |hash, key| hash[key] }
+ keys.inject(@@api_fixtures[name]) { |hash, key| hash[key].deep_dup }
end
end
def api_fixture(name, *keys)
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list