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=499c365b1be9df571ff65e29ff57b57b0551274d;hp=391f031ac10e49bdd0b53a4a89ed4399a8feb154;hb=804143deca6f2bebfc87cc78cf397201b6028bc5;hpb=8c25d85b1c79a9671c0e81e65c5ff5c112e8399f diff --git a/t/optional_memleak.t b/t/optional_memleak.t index 391f031..499c365 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 Proc::ProcessTable"; -plan skip_all => 'set TEST_MEMLEAK to enable this test' - unless $ENV{TEST_MEMLEAK}; +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 $t = Proc::ProcessTable->new( cache_ttys => 1 ); -our ( $initial, $final ) = ( 0, 0 ); -our $tests = YAML::LoadFile("$FindBin::Bin/optional_stress.yml"); +our ( $initial, $final ) = ( 0, 0 ); +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; @@ -34,7 +38,7 @@ if ( $user_test ) { else { 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 ); @@ -44,40 +48,40 @@ else { sub run_test { my $uri = shift || die 'No URI given for test'; - + print "TESTING $uri\n"; - + # make a few requests to set initial memory size for ( 1 .. 3 ) { request( $uri ); } - + $initial = size_of($$); print "Initial Size: $initial\n"; - + for ( 1 .. 500 ) { request( $uri ); } - + $final = size_of($$); print "Final Size: $final\n"; - + if ( $final > $initial ) { - print "Leaked: " . ($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?"; }