X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cae94f22b760c6c6899fc4d23db15d389535ff0a..24bcfa0b87b87e4510fffe8a961a5d4a9fd34948:/services/api/test/unit/container_request_test.rb diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb index e44084eaf3..3b17574237 100644 --- a/services/api/test/unit/container_request_test.rb +++ b/services/api/test/unit/container_request_test.rb @@ -202,7 +202,7 @@ class ContainerRequestTest < ActiveSupport::TestCase test "Request is finalized when its container is cancelled" do set_user_from_auth :active - cr = create_minimal_req!(priority: 1, state: "Committed") + cr = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 1) act_as_system_user do Container.find_by_uuid(cr.container_uuid). @@ -215,7 +215,10 @@ class ContainerRequestTest < ActiveSupport::TestCase test "Request is finalized when its container is completed" do set_user_from_auth :active - cr = create_minimal_req!(priority: 1, state: "Committed") + project = groups(:private) + cr = create_minimal_req!(owner_uuid: project.uuid, + priority: 1, + state: "Committed") c = act_as_system_user do c = Container.find_by_uuid(cr.container_uuid) @@ -228,22 +231,30 @@ class ContainerRequestTest < ActiveSupport::TestCase assert_equal "Committed", cr.state act_as_system_user do - c.update_attributes!(state: Container::Complete) + c.update_attributes!(state: Container::Complete, + output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45', + log: 'fa7aeb5140e2848d39b416daeef4ffc5+45') end cr.reload assert_equal "Final", cr.state + ['output', 'log'].each do |out_type| + pdh = Container.find_by_uuid(cr.container_uuid).send(out_type) + assert_equal(1, Collection.where(portable_data_hash: pdh, + owner_uuid: project.uuid).count, + "Container #{out_type} should be copied to #{project.uuid}") + end end test "Container makes container request, then is cancelled" do set_user_from_auth :active - cr = create_minimal_req!(priority: 5, state: "Committed") + cr = create_minimal_req!(priority: 5, state: "Committed", container_count_max: 1) c = Container.find_by_uuid cr.container_uuid assert_equal 5, c.priority cr2 = create_minimal_req! - cr2.update_attributes!(priority: 10, state: "Committed", requesting_container_uuid: c.uuid, command: ["echo", "foo2"]) + cr2.update_attributes!(priority: 10, state: "Committed", requesting_container_uuid: c.uuid, command: ["echo", "foo2"], container_count_max: 1) cr2.reload c2 = Container.find_by_uuid cr2.container_uuid @@ -432,4 +443,42 @@ class ContainerRequestTest < ActiveSupport::TestCase create_minimal_req!(state: "Uncommitted", priority: 1, requesting_container_uuid: 'youcantdothat') end end + + test "Retry on container cancelled" do + set_user_from_auth :active + cr = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 2) + prev_container_uuid = cr.container_uuid + + c = act_as_system_user do + c = Container.find_by_uuid(cr.container_uuid) + c.update_attributes!(state: Container::Locked) + c.update_attributes!(state: Container::Running) + c + end + + cr.reload + assert_equal "Committed", cr.state + assert_equal prev_container_uuid, cr.container_uuid + prev_container_uuid = cr.container_uuid + + act_as_system_user do + c.update_attributes!(state: Container::Cancelled) + end + + cr.reload + assert_equal "Committed", cr.state + assert_not_equal prev_container_uuid, cr.container_uuid + prev_container_uuid = cr.container_uuid + + c = act_as_system_user do + c = Container.find_by_uuid(cr.container_uuid) + c.update_attributes!(state: Container::Cancelled) + c + end + + cr.reload + assert_equal "Final", cr.state + assert_equal prev_container_uuid, cr.container_uuid + end + end