[ARVADOS] updated: df439a7eb705da7aae720a43c85c462cc6235e5a
git at public.curoverse.com
git at public.curoverse.com
Thu Dec 3 18:51:48 EST 2015
Summary of changes:
services/api/app/models/container.rb | 18 +++++--
services/api/test/unit/container_test.rb | 84 +++++++++++++++++++++++++++++++-
2 files changed, 97 insertions(+), 5 deletions(-)
via df439a7eb705da7aae720a43c85c462cc6235e5a (commit)
from d1baf718d0866c64252006bf61a6f0c5da353f7b (commit)
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 df439a7eb705da7aae720a43c85c462cc6235e5a
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Thu Dec 3 18:49:14 2015 -0500
Finish basic state change & record protection unit tests.
diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index a0ac077..9499d89 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -46,7 +46,9 @@ class Container < ArvadosModel
self.state ||= Queued
self.environment ||= {}
self.runtime_constraints ||= {}
+ self.mounts ||= {}
self.cwd ||= "."
+ self.priority ||= 1
end
end
@@ -102,16 +104,24 @@ class Container < ArvadosModel
errors.add :state, "Can only go to Runinng from Queued"
end
else
- permitted.push :progress
+ permitted.push :priority, :progress
end
- when Complete, Cancelled
+ when Complete
+ if self.state_changed?
+ if self.state_was == Running
+ permitted.push :state, :finished_at, :output, :log
+ else
+ errors.add :state, "Cannot go from #{self.state_was} from #{self.state}"
+ end
+ end
+ when Cancelled
if self.state_changed?
if self.state_was == Running
permitted.push :state, :finished_at, :output, :log
elsif self.state_was == Queued
- permitted.push :state
+ permitted.push :state, :finished_at
else
- errors.add :state, "Can only go to #{self.state} from Running"
+ errors.add :state, "Cannot go from #{self.state_was} from #{self.state}"
end
end
else
diff --git a/services/api/test/unit/container_test.rb b/services/api/test/unit/container_test.rb
index c635af3..7d8d8f0 100644
--- a/services/api/test/unit/container_test.rb
+++ b/services/api/test/unit/container_test.rb
@@ -60,6 +60,36 @@ class ContainerTest < ActiveSupport::TestCase
end
end
+ def check_no_change_from_complete c
+ check_illegal_modify c
+ check_bogus_states c
+
+ assert_raises(ActiveRecord::RecordInvalid) do
+ c.reload
+ c.priority = 3
+ c.save!
+ end
+
+ assert_raises(ActiveRecord::RecordInvalid) do
+ c.reload
+ c.state = "Queued"
+ c.save!
+ end
+
+ assert_raises(ActiveRecord::RecordInvalid) do
+ c.reload
+ c.state = "Running"
+ c.save!
+ end
+
+ assert_raises(ActiveRecord::RecordInvalid) do
+ c.reload
+ c.state = "Complete"
+ c.save!
+ end
+
+ end
+
test "Container create" do
act_as_system_user do
c = Container.new
@@ -67,7 +97,7 @@ class ContainerTest < ActiveSupport::TestCase
c.container_image = "img"
c.cwd = "/tmp"
c.environment = {}
- c.mounts = {}
+ c.mounts = {"BAR" => "FOO"}
c.output_path = "/tmp"
c.priority = 1
c.runtime_constraints = {}
@@ -79,6 +109,22 @@ class ContainerTest < ActiveSupport::TestCase
c.reload
c.priority = 2
c.save!
+ end
+ end
+
+ test "Container running" do
+ act_as_system_user do
+ c = Container.new
+ c.command = ["echo", "foo"]
+ c.container_image = "img"
+ c.output_path = "/tmp"
+ c.save!
+
+ assert_raises(ActiveRecord::RecordInvalid) do
+ c.reload
+ c.state = "Complete"
+ c.save!
+ end
c.reload
c.state = "Running"
@@ -96,7 +142,43 @@ class ContainerTest < ActiveSupport::TestCase
c.reload
c.priority = 3
c.save!
+ end
+ end
+
+ test "Container queued cancel" do
+ act_as_system_user do
+ c = Container.new
+ c.command = ["echo", "foo"]
+ c.container_image = "img"
+ c.output_path = "/tmp"
+ c.save!
+ c.reload
+ c.state = "Cancelled"
+ c.save!
+
+ check_no_change_from_complete c
end
end
+
+ test "Container running cancel" do
+ act_as_system_user do
+ c = Container.new
+ c.command = ["echo", "foo"]
+ c.container_image = "img"
+ c.output_path = "/tmp"
+ c.save!
+
+ c.reload
+ c.state = "Running"
+ c.save!
+
+ c.reload
+ c.state = "Cancelled"
+ c.save!
+
+ check_no_change_from_complete c
+ end
+ end
+
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list