12414: Enhance sweep process test to ensure no unwanted deletions happen
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 2 Apr 2018 18:53:40 +0000 (15:53 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 2 Apr 2018 18:53:40 +0000 (15:53 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/api/lib/sweep_trashed_objects.rb
services/api/test/fixtures/jobs.yml
services/api/test/unit/group_test.rb

index c4db856f5195f144c003780380572950401e293f..857662ac37b1900765debbf8347a9e14586f6589 100644 (file)
@@ -20,7 +20,7 @@ module SweepTrashedObjects
     # exceptions, and delete records owned by this project
     skipped_classes = ['Group', 'User']
     ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |klass|
-      if !skipped_classes.include?(klass.name) && klass.columns.collect{|c| c.name}.include?('owner_uuid')
+      if !skipped_classes.include?(klass.name) && klass.columns.collect{&:name}.include?('owner_uuid')
         klass.where({owner_uuid: p_uuid}).destroy_all
       end
     end
index 4b26edc83791eadfece909653187db9574d2efe9..140f3708398fb8735363c977b10dfe00996bf465 100644 (file)
@@ -418,7 +418,7 @@ job_in_subproject:
 job_in_trashed_project:
   uuid: zzzzz-8i9sb-subprojectjob02
   created_at: 2014-10-15 12:00:00
-  owner_uuid: zzzzz-j7d0g-trashedproject1
+  owner_uuid: zzzzz-j7d0g-trashedproject2
   log: ~
   repository: active/foo
   script: hash
index 892086b1994e7d5bd663c665023855c017c2fe02..554106e0063eef3717c8958e59618222c7e876a7 100644 (file)
@@ -203,6 +203,13 @@ class GroupTest < ActiveSupport::TestCase
     col = collections(:collection_in_trashed_subproject)
     job = jobs(:job_in_trashed_project)
     cr = container_requests(:cr_in_trashed_project)
+    # Save how many objects were before the sweep
+    user_nr_was = User.all.length
+    coll_nr_was = Collection.all.length
+    group_nr_was = Group.where('group_class != "project"').length
+    project_nr_was = Group.where(group_class: "project").length
+    cr_nr_was = CollectionRequest.all.length
+    job_nr_was = Job.all.length
     assert_not_empty Group.where(uuid: g_foo.uuid)
     assert_not_empty Group.where(uuid: g_bar.uuid)
     assert_not_empty Group.where(uuid: g_baz.uuid)
@@ -216,5 +223,12 @@ class GroupTest < ActiveSupport::TestCase
     assert_empty Collection.where(uuid: col.uuid)
     assert_empty Job.where(uuid: job.uuid)
     assert_empty ContainerRequest.where(uuid: cr.uuid)
+    # No unwanted deletions should have happened
+    assert_equal user_nr_was, User.all.length
+    assert_equal coll_nr_was-1, Collection.all.length
+    assert_equal group_nr_was, Group.where('group_class != "project"').length
+    assert_equal project_nr_was-3, Group.where(group_class: "project").length
+    assert_equal cr_nr_was-1, CollectionRequest.all.length
+    assert_equal job_nr_was-1, Job.all.length
   end
 end