Combined memleak test with stress test to test all test actions
[catagits/Catalyst-Runtime.git] / t / optional / memleak.t
CommitLineData
7c40a30f 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/../live/lib";
8
9use Test::More;
10use Catalyst::Test 'TestApp';
010c814d 11use YAML;
11956eee 12eval "use GTop";
7c40a30f 13
14plan skip_all => 'set TEST_MEMLEAK to enable this test'
15 unless $ENV{TEST_MEMLEAK};
16plan skip_all => 'GTop required for this test' if $@;
17
010c814d 18our $gtop = GTop->new;
19our ( $initial, $final ) = ( 0, 0 );
20our $tests = YAML::LoadFile("$FindBin::Bin/stress.yml");
7c40a30f 21
010c814d 22my $total_tests = 0;
23map { $total_tests += scalar @{ $tests->{$_} } } keys %{$tests};
24plan tests => $total_tests;
25
26foreach my $test_group ( keys %{$tests} ) {
27 foreach my $test ( @{ $tests->{$test_group} } ) {
28 run_test( $test );
29 }
30}
31
32sub run_test {
33 my $uri = shift || die 'No URI given for test';
7c40a30f 34
010c814d 35 print "TESTING $uri\n";
36
37 # make a few requests to set initial memory size
38 for ( 1 .. 3 ) {
39 request( $uri );
40 }
41
42 $initial = $gtop->proc_mem($$)->size;
c6294ccd 43 print "Initial Size: " . GTop::size_string($initial) . "\n";
7c40a30f 44
010c814d 45 for ( 1 .. 500 ) {
46 request( $uri );
7c40a30f 47 }
48
010c814d 49 $final = $gtop->proc_mem($$)->size;
c6294ccd 50 print "Final Size: " . GTop::size_string($final) . "\n";
7c40a30f 51
52 if ( $final > $initial ) {
c6294ccd 53 print "Leaked Bytes: " . GTop::size_string($final - $initial) . "\n";
7c40a30f 54 }
55
010c814d 56 is( $final, $initial, "'$uri' memory is not leaking" );
7c40a30f 57}
010c814d 58