9687: Updated state_label method changes to something more simple and compact. Added...
authorLucas Di Pentima <lucas@curoverse.com>
Mon, 29 Aug 2016 20:50:58 +0000 (17:50 -0300)
committerLucas Di Pentima <lucas@curoverse.com>
Mon, 29 Aug 2016 20:50:58 +0000 (17:50 -0300)
apps/workbench/app/models/container_work_unit.rb
apps/workbench/test/unit/work_unit_test.rb
services/api/test/fixtures/containers.yml

index 43871c51515a2b63d004cee099e6caa368cff2c8..2102a129ea4dbc7b1839c579d81a2adaa26b4ad9 100644 (file)
@@ -75,14 +75,9 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def state_label
-    if @proxied.is_a? ContainerRequest and
-       get(:state) == "Committed" and
-       get(:state, @container) == "Complete" and
-       get(:exit_code, @container) != 0
-      "Failed"
-    else
-      get_combined(:state)
-    end
+    exit_code = get_combined(:exit_code)
+    "Failed" if (exit_code && exit_code != 0)
+    get_combined(:state)
   end
 
   def docker_image
index 236e7a2d9e98951ed976293b5a2a5e7052cdb0cb..5d4c77c426c4254a1660922d3a0612e0388ce534 100644 (file)
@@ -35,11 +35,16 @@ class WorkUnitTest < ActiveSupport::TestCase
     end
   end
 
-  test "state_label should be Failed if container exit_code not 0" do
-    use_token 'active'
-    obj = find_fixture(ContainerRequest, 'cr_for_failed')
-    wu = obj.work_unit
-    assert_equal "Failed", wu.state_label
+  [
+    ['cr_for_failed', true],
+    ['completed', false],
+  ].each do |cr_fixture, should_be_Failed|
+    test "state_label of ContainerRequest #{cr_fixture}" do
+      use_token 'active'
+      obj = find_fixture(ContainerRequest, cr_fixture)
+      wu = obj.work_unit
+      assert_equal should_be_Failed, ("Failed" == wu.state_label)
+    end
   end
 
   [
index f9d18be42ebeb308c5e46001a5f26f712d8551c7..049cd3c6db0307d7ce029f641f8dc93fb8ce917e 100644 (file)
@@ -69,6 +69,7 @@ completed:
   uuid: zzzzz-dz642-compltcontainer
   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   state: Complete
+  exit_code: 0
   priority: 1
   created_at: 2016-01-11 11:11:11.111111111 Z
   updated_at: 2016-01-11 11:11:11.111111111 Z
@@ -88,6 +89,7 @@ completed_older:
   uuid: zzzzz-dz642-compltcontainr2
   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   state: Complete
+  exit_code: 0
   priority: 1
   created_at: 2016-01-11 11:11:11.111111111 Z
   updated_at: 2016-01-11 11:11:11.111111111 Z
@@ -106,6 +108,7 @@ requester:
   uuid: zzzzz-dz642-requestingcntnr
   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   state: Complete
+  exit_code: 0
   priority: 1
   created_at: 2016-01-11 11:11:11.111111111 Z
   updated_at: 2016-01-11 11:11:11.111111111 Z
@@ -122,6 +125,7 @@ requester_container:
   uuid: zzzzz-dz642-requestercntnr1
   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   state: Complete
+  exit_code: 0
   priority: 1
   created_at: 2016-01-11 11:11:11.111111111 Z
   updated_at: 2016-01-11 11:11:11.111111111 Z