From 343d624bd59cba06a5b4b706cb1b45799fcd4013 Mon Sep 17 00:00:00 2001 From: Trevor Ackerman Date: Mon, 29 Feb 2016 15:10:56 -0700 Subject: [PATCH 1/2] Traffic Ops - test helper module now properly deletes cachegroups without relying on order of ids --- traffic_ops/app/lib/Test/TestHelper.pm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/traffic_ops/app/lib/Test/TestHelper.pm b/traffic_ops/app/lib/Test/TestHelper.pm index 4c14b6cfc..c4feece65 100644 --- a/traffic_ops/app/lib/Test/TestHelper.pm +++ b/traffic_ops/app/lib/Test/TestHelper.pm @@ -145,10 +145,21 @@ sub teardown { sub teardown_cachegroup { my $self = shift; my $schema = shift; - my $cachegroups = - $schema->resultset("Cachegroup")->search( undef, { order_by => { -desc => [qw{parent_cachegroup_id secondary_parent_cachegroup_id}] } } ); - while ( my $row = $cachegroups->next ) { - $row->delete(); + + my $cachegroups = $schema->resultset("Cachegroup"); + while ( $cachegroups ne 0 ) { + while ( my $row = $cachegroups->next ) { + if ( $schema->resultset("Cachegroup")->count({parent_cachegroup_id => $row->id}) ne 0 ) { + next; + } + + if ( $schema->resultset("Cachegroup")->count({secondary_parent_cachegroup_id => $row->id}) ne 0 ) { + next; + } + + $row->delete(); + } + $cachegroups = $schema->resultset("Cachegroup"); } } From 4bfbc302ce042640f1fc995f6b3060c4cb124af8 Mon Sep 17 00:00:00 2001 From: Trevor Ackerman Date: Wed, 2 Mar 2016 07:48:12 -0700 Subject: [PATCH 2/2] Use do...while loop in test helper --- traffic_ops/app/lib/Test/TestHelper.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/traffic_ops/app/lib/Test/TestHelper.pm b/traffic_ops/app/lib/Test/TestHelper.pm index c4feece65..37828fc2f 100644 --- a/traffic_ops/app/lib/Test/TestHelper.pm +++ b/traffic_ops/app/lib/Test/TestHelper.pm @@ -146,21 +146,22 @@ sub teardown_cachegroup { my $self = shift; my $schema = shift; - my $cachegroups = $schema->resultset("Cachegroup"); - while ( $cachegroups ne 0 ) { + my $cachegroups; + do { + $cachegroups = $schema->resultset("Cachegroup"); while ( my $row = $cachegroups->next ) { - if ( $schema->resultset("Cachegroup")->count({parent_cachegroup_id => $row->id}) ne 0 ) { + if ( $schema->resultset("Cachegroup")->count({parent_cachegroup_id => $row->id}) > 0 ) { next; } - if ( $schema->resultset("Cachegroup")->count({secondary_parent_cachegroup_id => $row->id}) ne 0 ) { + if ( $schema->resultset("Cachegroup")->count({secondary_parent_cachegroup_id => $row->id}) > 0 ) { next; } $row->delete(); } - $cachegroups = $schema->resultset("Cachegroup"); - } + + } while ( $cachegroups->count() > 0 ); } 1;