Skip to content

Commit

Permalink
fixed small state bug in Mojo::Transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 1, 2012
1 parent be38d5b commit 1cebd7a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@
3.37 2012-09-01
- Updated jQuery to version 1.8.1.
- Improved documentation.
- Fixed small state bug in Mojo::Transaction.

3.36 2012-08-30
- Improved documentation.
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/Transaction.pm
Expand Up @@ -64,7 +64,9 @@ sub resume {
return $self->emit('resume');
}

sub server_close { shift->emit('finish') }
sub server_close {
shift->tap(sub { $_->{state} = 'finished' })->emit('finish');
}

sub server_read { croak 'Method "server_read" not implemented by subclass' }
sub server_write { croak 'Method "server_write" not implemented by subclass' }
Expand Down
10 changes: 6 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 => 109;
use Test::More tests => 111;

use Mojo::IOLoop;
use Mojo::UserAgent;
Expand Down Expand Up @@ -188,7 +188,7 @@ ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# GET / (callbacks)
# GET / (events)
my $finished;
$tx = $ua->build_tx(GET => '/');
$ua->once(
Expand All @@ -198,14 +198,16 @@ $ua->once(
}
);
$tx = $ua->start($tx);
ok $tx->success, 'successful';
ok $tx->success, 'successful';
ok $tx->is_finished, 'transaction is finished';
is $finished, 1, 'finish event has been emitted';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# GET /no_length (missing Content-Length header)
$tx = $ua->get('/no_length');
ok $tx->success, 'successful';
ok $tx->success, 'successful';
ok $tx->is_finished, 'transaction is finished';
ok !$tx->error, 'no error';
ok $tx->kept_alive, 'kept connection alive';
ok !$tx->keep_alive, 'keep connection not alive';
Expand Down

0 comments on commit 1cebd7a

Please sign in to comment.