[Rt-commit] rt branch, 4.0/stop-shredder-dataloss, created. rt-4.0.5-137-g5bdf351

Jim Brandt jbrandt at bestpractical.com
Tue Aug 7 12:34:05 EDT 2012


The branch, 4.0/stop-shredder-dataloss has been created
        at  5bdf3519b0c2fa28ed22f9a940bcb07341928504 (commit)

- Log -----------------------------------------------------------------
commit 361934d3fd4d2ac73796f9afb13b42c0ed85ae94
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Aug 7 10:24:19 2012 -0400

    Update table_info call to get back table data for test SQLite DB
    
    The dump_current_and_savepoint function in shredder/utils.pl relies
    on the table_info call from DBD::SQLite to return all of the tables in
    the test RT database. The call was using empty strings as the first
    two parameters, but instead of returning all tables, it returned none.
    
    The first parameter is catalog which isn't supported in SQLite,
    and the second, schema, seemed to be performing a LIKE and matching
    nothing.
    
    Based on the examples in the DBD::SQLite tests, passing undef
    for the first two parameters and '%' for the third parameter, table,
    returns all tables.
    
    This change returns data for the test comparison and in
    doing so reveals a failing test in t/shredder/01ticket.t

diff --git a/t/shredder/utils.pl b/t/shredder/utils.pl
index 5f5c182..9b848c6 100644
--- a/t/shredder/utils.pl
+++ b/t/shredder/utils.pl
@@ -283,7 +283,7 @@ sub dump_sqlite
     my $old_fhkn = $dbh->{'FetchHashKeyName'};
     $dbh->{'FetchHashKeyName'} = 'NAME_lc';
 
-    my $sth = $dbh->table_info( '', '', '%', 'TABLE' ) || die $DBI::err;
+    my $sth = $dbh->table_info( '', '%', '%', 'TABLE' ) || die $DBI::err;
     my @tables = keys %{$sth->fetchall_hashref( 'table_name' )};
 
     my $res = {};

commit 09d7d4e564be48be6ba85ab36d8385ba1cf02c12
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Aug 7 10:35:45 2012 -0400

    Make shredder test TODO for remaining transaction and link after shred
    
    The table_info fix in 361934d3 revealed that transactions and links
    remain after a child ticket has been shredded. Marking test as
    a todo.

diff --git a/t/shredder/01ticket.t b/t/shredder/01ticket.t
index 7dff16d..a7abeef 100644
--- a/t/shredder/01ticket.t
+++ b/t/shredder/01ticket.t
@@ -78,7 +78,11 @@ cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"
     my $shredder = shredder_new();
     $shredder->PutObjects( Objects => $child );
     $shredder->WipeoutAll;
-    cmp_deeply( dump_current_and_savepoint('parent_ticket'), "current DB equal to savepoint");
+
+  TODO: {
+        local $TODO = "Shredder doesn't delete all links and transactions";
+        cmp_deeply( dump_current_and_savepoint('parent_ticket'), "current DB equal to savepoint");
+    }
 
     $shredder->PutObjects( Objects => $parent );
     $shredder->WipeoutAll;

commit 5bdf3519b0c2fa28ed22f9a940bcb07341928504
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Aug 7 10:43:44 2012 -0400

    Loop with values, not each, in WipeoutAll to avoid side effects
    
    Wipeout works to remove items from the shredder cache, so it
    can delete entries from the hash before the iterator used by
    each gets there. From perldoc -f each:
    
    "If you add or delete a hash’s elements while iterating over it,
    entries may be skipped or duplicated‐‐so don’t do that."
    
    Converted to values, which does not use the iterator.
    
    See also:
    
    http://issues.bestpractical.com/Ticket/Display.html?id=16070
    
    Original branch provided by Bradley Bell:
    https://github.com/btb/rt/tree/4.0/stop-shredder-dataloss

diff --git a/lib/RT/Shredder.pm b/lib/RT/Shredder.pm
index 10d3536..7ca2c94 100644
--- a/lib/RT/Shredder.pm
+++ b/lib/RT/Shredder.pm
@@ -537,9 +537,9 @@ sub WipeoutAll
 {
     my $self = $_[0];
 
-    while ( my ($k, $v) = each %{ $self->{'cache'} } ) {
-        next if $v->{'State'} & (WIPED | IN_WIPING);
-        $self->Wipeout( Object => $v->{'Object'} );
+    foreach my $cache_val ( values %{ $self->{'cache'} } ) {
+        next if $cache_val->{'State'} & (WIPED | IN_WIPING);
+        $self->Wipeout( Object => $cache_val->{'Object'} );
     }
 }
 
diff --git a/t/shredder/03plugin_users.t b/t/shredder/03plugin_users.t
index 4f4ecc8..1f4cb49 100644
--- a/t/shredder/03plugin_users.t
+++ b/t/shredder/03plugin_users.t
@@ -5,8 +5,8 @@ use warnings;
 
 use Test::Deep;
 use File::Spec;
-use Test::More tests => 9;
-use RT::Test nodb => 1;
+use Test::More tests => 21;
+use RT::Test ();
 BEGIN {
     my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
         File::Spec->curdir());
@@ -38,3 +38,61 @@ use_ok('RT::Shredder::Plugin::Users');
     ok(!$status, "bad 'status' arg value");
 }
 
+init_db();
+
+RT::Test->set_rights(
+    { Principal => 'Everyone', Right => [qw(CreateTicket)] },
+);
+
+create_savepoint('clean');
+
+{ # Create two users and a ticket. Shred second user and replace relations with first user
+    my ($uidA, $uidB, $msg);
+    my $userA = RT::User->new( RT->SystemUser );
+    ($uidA, $msg) = $userA->Create( Name => 'userA', Privileged => 1, Disabled => 0 );
+    ok( $uidA, "created user A" ) or diag "error: $msg";
+
+    my $userB = RT::User->new( RT->SystemUser );
+    ($uidB, $msg) = $userB->Create( Name => 'userB', Privileged => 1, Disabled => 0 );
+    ok( $uidB, "created user B" ) or diag "error: $msg";
+
+    my ($tid, $trid);
+    my $ticket = RT::Ticket->new( RT::CurrentUser->new($userB) );
+    ($tid, $trid, $msg) = $ticket->Create( Subject => 'UserB Ticket', Queue => 1 );
+    ok( $tid, "created new ticket") or diag "error: $msg";
+
+    my $transaction = RT::Transaction->new( RT->SystemUser );
+    $transaction->Load($trid);
+    is ( $transaction->Creator, $uidB, "ticket creator is user B" );
+
+    my $plugin = RT::Shredder::Plugin::Users->new;
+    isa_ok($plugin, 'RT::Shredder::Plugin::Users');
+
+    my $status;
+    ($status, $msg) = $plugin->TestArgs( status => 'any', name => 'userB', replace_relations => $uidA );
+    ok($status, "plugin arguments are ok") or diag "error: $msg";
+
+    my @objs;
+    ($status, @objs) = $plugin->Run;
+    ok($status, "executed plugin successfully") or diag "error: @objs";
+    @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
+    is(scalar @objs, 1, "one object in the result set");
+
+    my $shredder = shredder_new();
+
+    ($status, $msg) = $plugin->SetResolvers( Shredder => $shredder );
+    ok($status, "set conflicts resolver") or diag "error: $msg";
+
+    $shredder->PutObjects( Objects => \@objs );
+    $shredder->WipeoutAll;
+
+    $ticket->Load( $tid );
+    is($ticket->id, $tid, 'loaded ticket');
+
+    $transaction->Load($trid);
+    is ( $transaction->Creator, $uidA, "ticket creator is now user A" );
+
+    $shredder->Wipeout( Object => $ticket );
+    $shredder->Wipeout( Object => $userA );
+}
+cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");

-----------------------------------------------------------------------


More information about the Rt-commit mailing list