[Bps-public-commit] r11341 - SVN-PropDB/lib/Prophet/Test

clkao at bestpractical.com clkao at bestpractical.com
Tue Apr 1 19:15:37 EDT 2008


Author: clkao
Date: Tue Apr  1 19:15:36 2008
New Revision: 11341

Modified:
   SVN-PropDB/lib/Prophet/Test/Arena.pm
   SVN-PropDB/lib/Prophet/Test/Participant.pm

Log:
record tests sanely so it can be replayed.


Modified: SVN-PropDB/lib/Prophet/Test/Arena.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test/Arena.pm	(original)
+++ SVN-PropDB/lib/Prophet/Test/Arena.pm	Tue Apr  1 19:15:36 2008
@@ -4,7 +4,7 @@
 
 package Prophet::Test::Arena;
 use base qw/Class::Accessor/;
-__PACKAGE__->mk_accessors(qw/chickens/);
+__PACKAGE__->mk_accessors(qw/chickens record_callback history/);
 
 use Acme::MetaSyntactic;
 use Prophet::Test;
@@ -12,25 +12,16 @@
 sub setup {
     my $self  = shift;
     my $count = shift;
-    # create a set of n test participants
-        # that should initialize their environments
+    my @names = ref $count ? @$count : Acme::MetaSyntactic->new->name(pause_id => $count);
 
-    my @chickens;
-
-    my $meta = Acme::MetaSyntactic->new();
-    
-    for my $name ($meta->name(pause_id => $count)) {
-        push @chickens,Prophet::Test::Participant->new( { name => $name, arena => $self } );
-
-    }
+    my @chickens = map { Prophet::Test::Participant->new( { name => $_, arena => $self } ) } @names;
     $self->chickens(@chickens);
-        
 }
 
 sub step {
     my $self = shift;
     my $step_name = shift || undef;
-    for my $chicken (@{$self->chickens}) {
+   for my $chicken (@{$self->chickens}) {
         as_user($chicken->name, sub {$chicken->take_one_step($step_name)});
     }
 
@@ -63,7 +54,7 @@
         next if $a->name eq $b->name;
         next if ($seen_pairs{$b->name."-".$a->name});
         diag($a->name, $b->name);
-           as_user($a->name, sub {$a->sync_from_peer($b) });
+           as_user($a->name, sub {$a->sync_from_peer({ from => $b->name }) });
         $seen_pairs{$a->name."-".$b->name} =1;
     }
 
@@ -82,6 +73,10 @@
         $stored->{result} = $self->{record_map}{ $result } =
             ++$self->{record_cnt};
     }
+    return $self->record_callback->($name, $action, $args)
+        if $self->record_callback;
+
+    # XXX: move to some kind of recorder class and make use of callback
     push @{$self->{history} ||= []}, [$name, $action, $stored];
 }
 

Modified: SVN-PropDB/lib/Prophet/Test/Participant.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test/Participant.pm	(original)
+++ SVN-PropDB/lib/Prophet/Test/Participant.pm	Tue Apr  1 19:15:36 2008
@@ -32,11 +32,10 @@
 my @CHICKEN_DO = qw(create_record create_record delete_record  update_record update_record update_record update_record update_record sync_from_peer sync_from_peer noop);
 
 sub take_one_step {
-    my $self = shift;
-    my $action = shift || (shuffle(@CHICKEN_DO))[0];
-    $self->$action();
-
-
+    my $self   = shift;
+    my $action = shift || ( shuffle(@CHICKEN_DO) )[0];
+    my $args   = shift;
+    $self->$action($args);
 }
 
 
@@ -108,25 +107,24 @@
     %{$args->{props}} =_permute_props(%props) unless $args->{props};
     %props = %{ $args->{props} };
 
-    $self->record_action('update_record', $args);
-
-    run_ok('prophet-node-update', [qw(--type Scratch --uuid), $args->{record},
-                                   map { '--'.$_ => $props{$_} } keys %props  ], $self->name. " updated a record");
-
+    run_ok( 'prophet-node-update',
+        [ qw(--type Scratch --uuid), $args->{record},
+            map { '--' . $_ => $props{$_} } keys %props ], $self->name . " updated a record" );
 
+    $self->record_action('update_record', $args);
 
 }
 sub sync_from_peer {
     my $self = shift;
-    my $lucky = shift || (shuffle(grep { $_->name ne $self->name} @{$self->arena->chickens}))[0];
-
-    $self->record_action('sync_from_peer', { from => $lucky->name } );
+    my $args = shift;
 
-  
-#    my $lucky = shift @peers;
-    eval { run_ok('prophet-merge', ['--prefer','to','--from', repo_uri_for($lucky->name), '--to', repo_uri_for($self->name)],  $self->name. " sync from " .$lucky->name." ran ok!"); };
+    my $from = $args->{from} ||= (shuffle(grep { $_->name ne $self->name} @{$self->arena->chickens}))[0]->name;
 
+    $self->record_action('sync_from_peer', $args);
 
+    eval { run_ok( 'prophet-merge',
+            [ '--prefer', 'to', '--from', repo_uri_for($from),
+                '--to', repo_uri_for($self->name) ], $self->name . " sync from " . $from . " ran ok!" ); };
 
 }
 



More information about the Bps-public-commit mailing list