X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Foptional_memleak.t;h=ca4cbcf2c6013d890f6fad11173de15c1cdcfb89;hp=bc5a5d4cc943fe02e46f0fe2ee8ce12cc9663197;hb=43b44b3a2ee087f00af6579d3b6ac63f8f645412;hpb=a2e038a1e9cbc0f1ea32b7087e6b47efe3af082f diff --git a/t/optional_memleak.t b/t/optional_memleak.t index bc5a5d4..ca4cbcf 100644 --- a/t/optional_memleak.t +++ b/t/optional_memleak.t @@ -1,26 +1,28 @@ -#!perl - use strict; use warnings; +use Test::More; +BEGIN { + plan skip_all => 'set TEST_MEMLEAK to enable this test' + unless $ENV{TEST_MEMLEAK}; +} + use FindBin; use lib "$FindBin::Bin/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 $@; +eval "use Proc::ProcessTable"; +plan skip_all => 'Proc::ProcessTable required for this test' if $@; eval "use HTTP::Body 0.03"; plan skip_all => 'HTTP::Body >= 0.03 required for this test' if $@; -our $gtop = GTop->new; +eval "use YAML"; +plan skip_all => 'YAML required for this test' if $@; + +our $t = Proc::ProcessTable->new( cache_ttys => 1 ); our ( $initial, $final ) = ( 0, 0 ); -our $tests = YAML::LoadFile("$FindBin::Bin/stress.yml"); +our $tests = YAML::LoadFile("$FindBin::Bin/optional_stress.yml"); my $total_tests = 0; @@ -52,20 +54,32 @@ sub run_test { request( $uri ); } - $initial = $gtop->proc_mem($$)->size; - print "Initial Size: " . GTop::size_string($initial) . "\n"; + $initial = size_of($$); + print "Initial Size: $initial\n"; for ( 1 .. 500 ) { request( $uri ); } - $final = $gtop->proc_mem($$)->size; - print "Final Size: " . GTop::size_string($final) . "\n"; + $final = size_of($$); + print "Final Size: $final\n"; if ( $final > $initial ) { - print "Leaked Bytes: " . GTop::size_string($final - $initial) . "\n"; + print "Leaked: " . ($final - $initial) . "K\n"; } is( $final, $initial, "'$uri' memory is not leaking" ); } +sub size_of { + my $pid = shift; + + foreach my $p ( @{ $t->table } ) { + if ( $p->pid == $pid ) { + return $p->rss; + } + } + + die "Pid $pid not found?"; +} +