[Bps-public-commit] smokingit-worker branch, master, updated. 6e81846c1223995e1322c425a2e3db0dfacb52fe

Alex Vandiver alexmv at bestpractical.com
Mon Feb 28 23:57:50 EST 2011


The branch, master has been updated
       via  6e81846c1223995e1322c425a2e3db0dfacb52fe (commit)
      from  0dc3325bea32cfad42c9088e47a01c3d2a6bb5ea (commit)

Summary of changes:
 lib/Smokingit/Worker.pm |   72 +++++++++++++++++++++++------------------------
 1 files changed, 35 insertions(+), 37 deletions(-)

- Log -----------------------------------------------------------------
commit 6e81846c1223995e1322c425a2e3db0dfacb52fe
Author: Alex Vandiver <alex at chmrr.net>
Date:   Thu Feb 17 01:48:36 2011 -0500

    Refector to use closures for bail-out and cleanup functions

diff --git a/lib/Smokingit/Worker.pm b/lib/Smokingit/Worker.pm
index b1f0d02..d6ac180 100644
--- a/lib/Smokingit/Worker.pm
+++ b/lib/Smokingit/Worker.pm
@@ -88,15 +88,28 @@ sub run_tests {
         chdir($project);
     }
 
-    # Check the SHA and check it out
-    warn "Now testing:\n";
-    if (system("git", "rev-parse", "-q", "--verify", $sha)) {
-        warn "No such SHA $sha in $project!\n";
-        $result->{error} = "Can't find SHA";
-        $self->client->do_task(post_results => freeze($result));
+    # Set up initial state for cleaning purposes
+    my @cleaners = map {"Smokingit::Worker::Clean::$_"->new}
+        qw/TmpFiles Postgres Mysql/;
+    # Closures for cleanup and error handling
+    my $cleanup = sub {
+        system("git", "clean", "-fxdq");
+        system("git", "reset", "--hard", "HEAD");
+        $_->clean for @cleaners;
         chdir("..");
         return undef;
-    }
+    };
+    my $error = sub {
+        $result->{error} = shift;
+        warn $result->{error} . "\n";
+        $self->client->do_task(post_results => freeze($result));
+        $cleanup->();
+    };
+
+    # Check the SHA and check it out
+    warn "Now testing:\n";
+    !system("git", "rev-parse", "-q", "--verify", $sha)
+        or return $error->("Can't find SHA $sha in $project!");
     system("git", "clean", "-fxdq");
     system("git", "reset", "--hard", "HEAD", "--quiet");
     system("git", "checkout", "-q", $sha);
@@ -118,25 +131,13 @@ sub run_tests {
         $config =~ s/\s*;?\s*\n+/ && /g;
         my $output = `($config) 2>&1`;
         my $ret = $?;
-        if ($ret) {
-            my $exit_val = $ret >> 8;
-            warn "Return value of $config from $project = $exit_val\n$output\n";
-            $result->{error} = "Configuration failed (exit value $exit_val)!\n\n"
-                . $output;
-            $self->client->do_task(post_results => freeze($result));
-
-            system("git", "clean", "-fxdq");
-            system("git", "reset", "--hard", "HEAD");
-            chdir("..");
-            return;
-        }
+        my $exit_val = $ret >> 8;
+        return $error->("Configuration failed (exit value $exit_val)!\n\n" . $output)
+            if $ret;
     }
 
-    # Set up initial state for cleaning purposes
-    my @cleaners = map {"Smokingit::Worker::Clean::$_"->new}
-        qw/TmpFiles Postgres Mysql/;
 
-    # Run the tests
+    # Progress indicator via Gearman
     my $done = 0;
     my @tests = glob($tests);
     my $harness = TAP::Harness->new( {
@@ -148,30 +149,27 @@ sub run_tests {
             $job->set_status(++$done,scalar(@tests));
         }
     );
+
     my $aggregator = eval {
         # Runtests apparently grows PERL5LIB -- local it so it doesn't
         # grow without bound
         local $ENV{PERL5LIB} = $ENV{PERL5LIB};
         $harness->runtests(@tests);
-    };
-    if (not $aggregator) {
-        $result->{error} = "Testing bailed out!\n\n$@",
-    } else {
-        # Tests were successful!  Shove back the frozen aggregator,
-        # stripping out the iterator coderefs first
-        $aggregator->{parser_for}{$_}{_iter} = undef
-            for keys %{$aggregator->{parser_for}};
-        $result->{aggregator} = $aggregator;
-    }
+    } or return $error->("Testing bailed out!\n\n$@");
+
+    # Tests were successful!  Strip out the iterator coderefs so
+    # we can serialize the aggregator, for ease of stats
+    # extraction
+    $aggregator->{parser_for}{$_}{_iter} = undef
+        for keys %{$aggregator->{parser_for}};
+    $result->{aggregator} = $aggregator;
 
     $self->client->do_task(post_results => freeze($result))
         or die "Can't send task!";
 
     # Clean out
-    system("git", "clean", "-fxdq");
-    system("git", "reset", "--hard", "HEAD");
-    $_->clean for @cleaners;
-    chdir("..");
+    $cleanup->();
+    return 1;
 }
 
 1;

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



More information about the Bps-public-commit mailing list