You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2003/03/03 04:42:06 UTC
cvs commit: modperl-2.0/t/filter/TestFilter out_str_declined.pm
stas 2003/03/02 19:42:06
Added: t/filter out_str_declined.t
t/filter/TestFilter out_str_declined.pm
Log:
add a test testing how the declined is handled in the output filters,
plus it also verifies that rflush and unbuffered print are handled
correctly (by counting the number of resulting filter invocations, which
happens for each bb sent)
Revision Changes Path
1.1 modperl-2.0/t/filter/out_str_declined.t
Index: out_str_declined.t
===================================================================
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil;
plan tests => 1;
my $expected = 11; # 10 flushes and 1 EOS bb
my $location = '/TestFilter::out_str_declined';
my $response = GET_BODY $location;
ok t_cmp($expected, $response, "an output filter handler returning DECLINED");
1.1 modperl-2.0/t/filter/TestFilter/out_str_declined.pm
Index: out_str_declined.pm
===================================================================
package TestFilter::out_str_declined;
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestUtil;
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Filter ();
use Apache::Const -compile => qw(OK DECLINED);
use constant READ_SIZE => 1024;
# make sure that if the input filter returns DECLINED without
# reading/printing data the data flow is not broken
sub decline {
my $filter = shift;
my $ctx = $filter->ctx;
$ctx->{invoked}++;
$filter->ctx($ctx);
# can't use $f->seen_eos, since we don't read the data, so
# we have to set the note on each invocation
$filter->r->notes->set(invoked => $ctx->{invoked});
#warn "decline filter was invoked $ctx->{invoked} times\n";
return Apache::DECLINED;
}
# this filter ignores all the data that comes through, though on the
# last invocation it prints how many times the filter 'decline' was called
# which it could count by itself, but we want to test that
# 'return Apache::DECLINED' works properly in output filters
sub black_hole {
my $filter = shift;
my $ctx = $filter->ctx;
$ctx->{invoked}++;
$filter->ctx($ctx);
#warn "black_hole filter was invoked $ctx->{invoked} times\n";
while ($filter->read(my $data, READ_SIZE)) {
#warn "black_hole data: $data\n";
# let the data fall between the chairs
}
if ($filter->seen_eos) {
my $invoked = $filter->r->notes->get('invoked') || 0;
$filter->print($invoked);
}
return Apache::OK;
}
sub response {
my $r = shift;
# just to make sure that print() won't flush, or we would get the
# count wrong
local $| = 0;
$r->content_type('text/plain');
for (1..10) {
$r->print("a"); # this buffers the data
$r->rflush; # this sends the data in the buffer + flush bucket
}
Apache::OK;
}
1;
__DATA__
SetHandler modperl
PerlResponseHandler TestFilter::out_str_declined::response
PerlOutputFilterHandler TestFilter::out_str_declined::decline
PerlOutputFilterHandler TestFilter::out_str_declined::black_hole