Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test request as well
  • Loading branch information
kraih committed Sep 3, 2012
1 parent f2c6f9d commit aedf3c2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions t/mojo/user_agent.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 118;
use Test::More tests => 122;

use Mojo::IOLoop;
use Mojo::UserAgent;
Expand Down Expand Up @@ -189,41 +189,46 @@ is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# GET / (events)
my ($finished_tx, $finished_res);
my ($finished_req, $finished_tx, $finished_res);
$tx = $ua->build_tx(GET => '/');
ok !$tx->is_finished, 'transaction is not finished';
$ua->once(
start => sub {
my ($self, $tx) = @_;
$tx->req->on(finish => sub { $finished_req++ });
$tx->on(finish => sub { $finished_tx++ });
$tx->res->on(finish => sub { $finished_res++ });
}
);
$tx = $ua->start($tx);
ok $tx->success, 'successful';
is $finished_req, 1, 'finish event has been emitted once';
is $finished_tx, 1, 'finish event has been emitted once';
is $finished_res, 1, 'finish event has been emitted once';
ok $tx->req->is_finished, 'request is finished';
ok $tx->is_finished, 'transaction is finished';
ok $tx->res->is_finished, 'response is finished';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# GET /no_length (missing Content-Length header)
($finished_tx, $finished_res) = undef;
($finished_req, $finished_tx, $finished_res) = undef;
$tx = $ua->build_tx(GET => '/no_length');
ok !$tx->is_finished, 'transaction is not finished';
$ua->once(
start => sub {
my ($self, $tx) = @_;
$tx->req->on(finish => sub { $finished_req++ });
$tx->on(finish => sub { $finished_tx++ });
$tx->res->on(finish => sub { $finished_res++ });

}
);
$tx = $ua->start($tx);
ok $tx->success, 'successful';
is $finished_req, 1, 'finish event has been emitted once';
is $finished_tx, 1, 'finish event has been emitted once';
is $finished_res, 1, 'finish event has been emitted once';
ok $tx->req->is_finished, 'request is finished';
ok $tx->is_finished, 'transaction is finished';
ok $tx->res->is_finished, 'response is finished';
ok !$tx->error, 'no error';
Expand Down

0 comments on commit aedf3c2

Please sign in to comment.