Created
July 13, 2013 22:03
-
-
Save ian-kent/5992399 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use POSIX qw( strftime ); | |
use Test::Mojo; | |
use Data::Dumper; | |
use Test::More; | |
hook after_build_tx => sub { | |
# print "AFTER BUILD TX\n"; | |
}; | |
get '/' => sub { | |
my $self = shift; | |
# print "START\n"; | |
Mojo::IOLoop->timer(5 => sub { | |
$self->render(text => strftime('%H:%M:%S', localtime)); | |
# print "END\n"; | |
}); | |
}; | |
get '/other' => sub { | |
my $self = shift; | |
# print "START OTHER\n"; | |
Mojo::IOLoop->timer(5 => sub { | |
$self->render(text => strftime('%H:%M:%S', localtime)); | |
# print "END OTHER\n"; | |
}); | |
}; | |
#app->start; | |
#exit; | |
my $t = Test::Mojo->new; | |
my $ua = Mojo::UserAgent->new; | |
my $delay = Mojo::IOLoop->delay(sub {}); | |
my @results = (); | |
for my $url ('/', '/other') { | |
my $end = $delay->begin(0); | |
$ua->get($url => sub { | |
my ($ua, $tx) = @_; | |
push @results, $tx->res->content->asset->{content}; | |
$end->(); | |
}); | |
} | |
$delay->wait; | |
#print Dumper \@results; | |
is $results[0], $results[1], 'Calling different routes with different URLs'; | |
# Both using the same route and same URL, first request blocks the second | |
@results = (); | |
for my $url ('/', '/') { | |
my $end = $delay->begin(0); | |
$ua->get($url => sub { | |
my ($ua, $tx) = @_; | |
push @results, $tx->res->content->asset->{content}; | |
$end->(); | |
}); | |
} | |
$delay->wait; | |
#print Dumper \@results; | |
is $results[0], $results[1], 'Calling same route and same URL'; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment