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=59e388c7d53c64e2bba863e915d375c84fe503be;hp=3bc2dba7cb60f2ad6369cbb6604096002af00303;hb=eefc03e12890c06c9a76d78b4d68e3b2ad781328;hpb=e63e8323d236b89babd06838c60881785154a600 diff --git a/t/optional_memleak.t b/t/optional_memleak.t index 3bc2dba..59e388c 100644 --- a/t/optional_memleak.t +++ b/t/optional_memleak.t @@ -1,26 +1,30 @@ -#!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 $@; +use JSON::MaybeXS qw(decode_json); -our $gtop = GTop->new; +our $t = Proc::ProcessTable->new( cache_ttys => 1 ); our ( $initial, $final ) = ( 0, 0 ); -our $tests = YAML::LoadFile("$FindBin::Bin/optional_stress.yml"); +my $test_data = do { + open my $fh, '<:raw', "$FindBin::Bin/optional_stress.json" or die "$!"; + local $/; + <$fh>; +}; + +our $tests = decode_json($test_data); my $total_tests = 0; @@ -52,20 +56,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?"; +} +