Skip to content
Browse files

Add LeakTrace test

  • Loading branch information...
1 parent f7bb15d commit fe4fa21b8d545c8bbf59f774d96021b07f53ae9e @stash committed Jun 29, 2011
Showing with 93 additions and 12 deletions.
  1. +1 −0 MANIFEST
  2. +18 −12 Makefile.PL
  3. +74 −0 t/55-psgi-leak.t
View
1 MANIFEST
@@ -43,6 +43,7 @@ t/51-psgi-streaming.t
t/52-psgi-iohandle.t
t/53-psgi-overloaded.t
t/54-psgix-io.t
+t/55-psgi-leak.t
t/60-plack.t
t/61-plack-suite.t
t/62-plack-runner.t
View
30 Makefile.PL
@@ -41,14 +41,22 @@ elsif ($ARGV[0] eq '-CPAN') {
$convert_deps = 0;
}
-# Convert optional Plack dependency to a real dependency if it's present at
-# build-time. (Fix: https://rt.cpan.org/Public/Bug/Display.html?id=65239)
-my $plack_req = 0.995;
-my $json_xs_req = 2.0;
-my $have_plack, $have_json_xs;
+# Convert optional Plack and other dependencies to a real dependency if it's
+# present at build-time. (Fix:
+# https://rt.cpan.org/Public/Bug/Display.html?id=65239)
+my %want = (
+ 'Plack' => 0.995,
+ 'JSON::XS' => 2.0,
+ 'Test::LeakTrace' => 0.13,
+ 'Test::TCP' => 1.12,
+);
+my %have;
+
if ($convert_deps) {
- $have_plack = eval 'require Plack; $Plack::VERSION >= 0.995';
- $have_json_xs = eval 'require JSON::XS; $JSON::XS::VERSION >= 2.0';
+ local $@;
+ while (my ($pkg,$ver) = each %want) {
+ $have{$pkg} = eval "require $pkg; \$$pkg\::VERSION >= $ver";
+ }
}
# Set this to false if you get core-dumps. Gives a pretty good perf boost for
@@ -86,18 +94,16 @@ WriteMakefile(ev_args(
'Guard' => 1.012,
'Test::More' => 0.94,
'Test::Fatal' => 0.003,
- 'Test::TCP' => 1.12,
+ map { $_ => $want{$_} } grep { /^Test::/ && $have{$_} } keys %want
},
PREREQ_PM => {
'EV' => 4.00,
'Scalar::Util' => 1.19,
- ($have_plack ? (Plack => $plack_req) : ()),
- ($have_json_xs ? ('JSON::XS' => $json_xs_req) : ()),
+ map { $_ => $want{$_} } grep { !/^Test::/ && $have{$_} } keys %want
},
META_MERGE => {
recommends => {
- ($have_plack ? () : (Plack => $plack_req)),
- ($have_json_xs ? () : ('JSON::XS' => $json_xs_req)),
+ map { $_ => $want{$_} } grep { !$have{$_} } keys %want
},
resources => {
repository => 'git://github.com/stash/Feersum.git',
View
74 t/55-psgi-leak.t
@@ -0,0 +1,74 @@
+#!perl
+use warnings;
+use strict;
+use constant CLIENTS => 10;
+use Test::More tests => 7 + 4*CLIENTS;
+
+BEGIN {
+ plan skip_all => "Need Test::LeakTrace >= 0.13 to run this test"
+ unless eval q{
+ require Test::LeakTrace; $Test::LeakTrace::VERSION >= 0.13
+ };
+}
+
+use lib 't'; use Utils;
+use Test::LeakTrace;
+BEGIN { use_ok('Feersum') };
+
+my ($socket,$port) = get_listen_socket();
+ok $socket, "made listen socket";
+
+my $evh = Feersum->new();
+{
+ no warnings 'redefine';
+ *Feersum::DIED = sub {
+ my $err = shift;
+ fail "Died during request handler: $err";
+ };
+}
+$evh->use_socket($socket);
+
+my $APP = <<'EOAPP';
+ my $app = sub {
+ return [200, ['Content-Type' => 'text/plain'], ['Hello ','World']];
+ };
+EOAPP
+
+my $app = eval $APP;
+ok $app, 'got an app' || diag $@;
+$evh->psgi_request_handler($app);
+
+
+my $cv = AE::cv;
+no_leaks_ok {
+ return unless $cv;
+
+ for my $n (1 .. CLIENTS) {
+ $cv->begin;
+ my $h; $h = simple_client GET => '/',
+ name => "($n)",
+ sub {
+ my ($body, $headers) = @_;
+ is $headers->{'Status'}, 200, "($n) Response OK";
+ is $headers->{'content-type'}, 'text/plain', "... ($n) is text";
+ is $body, 'Hello World', "... ($n) correct body";
+ $cv->end;
+ undef $h;
+ };
+
+ }
+
+ $cv->recv;
+ pass "done requests";
+ $cv = undef;
+} 'request leaks';
+
+$cv = AE::cv;
+no_leaks_ok {
+ return unless $cv;
+ $evh->graceful_shutdown(sub { $cv->send });
+ $cv->recv;
+ pass "done graceful shutdown";
+ undef $cv;
+ undef $evh;
+} 'graceful shutdown leaks';

0 comments on commit fe4fa21

Please sign in to comment.
Something went wrong with that request. Please try again.