Combined memleak test with stress test to test all test actions
Andy Grundman [Wed, 26 Oct 2005 19:19:27 +0000 (19:19 +0000)]
t/optional/memleak.t

index 9731bb7..d5de6ff 100644 (file)
@@ -8,32 +8,51 @@ use lib "$FindBin::Bin/../live/lib";
 
 use Test::More;
 use Catalyst::Test 'TestApp';
+use YAML;
 eval "use GTop";
 
 plan skip_all => 'set TEST_MEMLEAK to enable this test'
     unless $ENV{TEST_MEMLEAK};
 plan skip_all => 'GTop required for this test' if $@;
 
-plan tests => 1;
+our $gtop = GTop->new;
+our ( $initial, $final ) = ( 0, 0 ); 
+our $tests = YAML::LoadFile("$FindBin::Bin/stress.yml");
 
-{
-    # make a request to set initial memory size
-    request('http://localhost');
+my $total_tests = 0;
+map { $total_tests += scalar @{ $tests->{$_} } } keys %{$tests};
+plan tests => $total_tests;
+
+foreach my $test_group ( keys %{$tests} ) {
+    foreach my $test ( @{ $tests->{$test_group} } ) {
+        run_test( $test );
+    }
+}
+
+sub run_test {
+    my $uri = shift || die 'No URI given for test';
     
-    my $gtop = GTop->new;
-    my $initial = $gtop->proc_mem($$)->size;
+    print "TESTING $uri\n";
+    
+    # make a few requests to set initial memory size
+    for ( 1 .. 3 ) {
+        request( $uri );
+    }
+    
+    $initial = $gtop->proc_mem($$)->size;
     print "Initial Size: " . GTop::size_string($initial) . "\n";
     
-    for ( 1 .. 1000 ) {
-        request('http://localhost');
+    for ( 1 .. 500 ) {
+        request( $uri );
     }
     
-    my $final = $gtop->proc_mem($$)->size;
+    $final = $gtop->proc_mem($$)->size;
     print "Final Size:   " . GTop::size_string($final) . "\n";
     
     if ( $final > $initial ) {
         print "Leaked Bytes: " . GTop::size_string($final - $initial) . "\n";
     }
     
-    is( $final, $initial, 'memory is not leaking' );
+    is( $final, $initial, "'$uri' memory is not leaking" );
 }
+