Commit | Line | Data |
---|---|---|
7c40a30f | 1 | use strict; |
2 | use warnings; | |
3 | ||
4853fb50 | 4 | use Test::More; |
5 | BEGIN { | |
6 | plan skip_all => 'set TEST_MEMLEAK to enable this test' | |
7 | unless $ENV{TEST_MEMLEAK}; | |
8 | } | |
9 | ||
7c40a30f | 10 | use FindBin; |
a2e038a1 | 11 | use lib "$FindBin::Bin/lib"; |
7c40a30f | 12 | use Catalyst::Test 'TestApp'; |
7c40a30f | 13 | |
15f0ede8 | 14 | eval "use Proc::ProcessTable"; |
9b984642 | 15 | plan skip_all => 'Proc::ProcessTable required for this test' if $@; |
7c40a30f | 16 | |
3eca4f18 | 17 | eval "use HTTP::Body 0.03"; |
18 | plan skip_all => 'HTTP::Body >= 0.03 required for this test' if $@; | |
19 | ||
15f0ede8 | 20 | eval "use YAML"; |
21 | plan skip_all => 'YAML required for this test' if $@; | |
22 | ||
9b984642 | 23 | our $t = Proc::ProcessTable->new( cache_ttys => 1 ); |
010c814d | 24 | our ( $initial, $final ) = ( 0, 0 ); |
e63e8323 | 25 | our $tests = YAML::LoadFile("$FindBin::Bin/optional_stress.yml"); |
7c40a30f | 26 | |
010c814d | 27 | my $total_tests = 0; |
010c814d | 28 | |
13af225c | 29 | # let the user specify a single uri to test |
30 | my $user_test = shift; | |
31 | if ( $user_test ) { | |
32 | plan tests => 1; | |
33 | run_test( $user_test ); | |
34 | } | |
35 | # otherwise, run all tests | |
36 | else { | |
37 | map { $total_tests += scalar @{ $tests->{$_} } } keys %{$tests}; | |
38 | plan tests => $total_tests; | |
39 | ||
40 | foreach my $test_group ( keys %{$tests} ) { | |
41 | foreach my $test ( @{ $tests->{$test_group} } ) { | |
42 | run_test( $test ); | |
43 | } | |
010c814d | 44 | } |
45 | } | |
46 | ||
47 | sub run_test { | |
48 | my $uri = shift || die 'No URI given for test'; | |
7c40a30f | 49 | |
010c814d | 50 | print "TESTING $uri\n"; |
51 | ||
52 | # make a few requests to set initial memory size | |
53 | for ( 1 .. 3 ) { | |
54 | request( $uri ); | |
55 | } | |
56 | ||
9b984642 | 57 | $initial = size_of($$); |
58 | print "Initial Size: $initial\n"; | |
7c40a30f | 59 | |
010c814d | 60 | for ( 1 .. 500 ) { |
61 | request( $uri ); | |
7c40a30f | 62 | } |
63 | ||
9b984642 | 64 | $final = size_of($$); |
65 | print "Final Size: $final\n"; | |
7c40a30f | 66 | |
67 | if ( $final > $initial ) { | |
0d9dfa69 | 68 | print "Leaked: " . ($final - $initial) . "K\n"; |
7c40a30f | 69 | } |
70 | ||
010c814d | 71 | is( $final, $initial, "'$uri' memory is not leaking" ); |
7c40a30f | 72 | } |
010c814d | 73 | |
9b984642 | 74 | sub size_of { |
75 | my $pid = shift; | |
76 | ||
77 | foreach my $p ( @{ $t->table } ) { | |
78 | if ( $p->pid == $pid ) { | |
fe796093 | 79 | return $p->rss; |
9b984642 | 80 | } |
81 | } | |
82 | ||
83 | die "Pid $pid not found?"; | |
84 | } | |
85 |