Navigation Menu

Skip to content

Commit

Permalink
fixed bug where Mojolicious::Lite applications in modules would gener…
Browse files Browse the repository at this point in the history
…ate the wrong moniker
  • Loading branch information
kraih committed Jan 7, 2013
1 parent 31faa34 commit ce256d3
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 54 deletions.
6 changes: 6 additions & 0 deletions Changes
@@ -1,4 +1,10 @@

3.74 2013-01-07
- Improved documentation.
- Improved tests.
- Fixed bug where Mojolicious::Lite applications in modules would generate
the wrong moniker.

3.73 2013-01-06
- Deprecated Mojolicious::Commands->start in favor of
Mojolicious::Commands->start_app.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -40,7 +40,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.73';
our $VERSION = '3.74';

sub AUTOLOAD {
my $self = shift;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Lite.pm
Expand Up @@ -24,7 +24,7 @@ sub import {

# Moniker
my $moniker = basename $ENV{MOJO_EXE};
$moniker =~ s/\.(?:pl|t)$//i;
$moniker =~ s/\.(?:pl|pm|t)$//i;
$app->moniker($moniker);

# Initialize routes
Expand Down
96 changes: 53 additions & 43 deletions t/mojo/app.t
Expand Up @@ -60,6 +60,7 @@ isa_ok $app->build_tx, 'Mojo::Transaction::HTTP', 'right class';
# Fresh application
$app = Mojolicious->new;
my $ua = Mojo::UserAgent->new(ioloop => Mojo::IOLoop->singleton)->app($app);
is $ua->app->moniker, 'mojolicious', 'right moniker';

# Silence
$app->log->level('fatal');
Expand Down Expand Up @@ -97,66 +98,42 @@ $app->routes->post(
);

# /*
$app->routes->any('/*whatever' => {text => 'Your Mojo is working!'});

# Pipelined
my $port = $ua->app_url->port;
my $buffer = '';
my $id;
$id = Mojo::IOLoop->client(
{port => $port} => sub {
my ($loop, $err, $stream) = @_;
$stream->on(
read => sub {
my ($stream, $chunk) = @_;
$buffer .= $chunk;
Mojo::IOLoop->remove($id) and Mojo::IOLoop->stop
if $buffer =~ s/ is working!.*is working!$//gs;
}
);
$stream->write("GET /pipeline1/ HTTP/1.1\x0d\x0a"
. "Content-Length: 0\x0d\x0a\x0d\x0a"
. "GET /pipeline2/ HTTP/1.1\x0d\x0a"
. "Content-Length: 0\x0d\x0a\x0d\x0a");
}
);
Mojo::IOLoop->start;
like $buffer, qr/Mojo$/, 'transactions were pipelined';
$app->routes->any('/*whatever' => {text => 'Whatever!'});

# Normal request
my $tx = $ua->get('/normal/');
ok $tx->keep_alive, 'will be kept alive';
is $tx->res->code, 200, 'right status';
like $tx->res->body, qr/Mojo/, 'right content';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Whatever!', 'right content';

# Keep alive request
$tx = $ua->get('/normal/');
ok $tx->keep_alive, 'will be kept alive';
ok $tx->kept_alive, 'was kept alive';
is $tx->res->code, 200, 'right status';
like $tx->res->body, qr/Mojo/, 'right content';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Whatever!', 'right content';

# Non keep alive request
$tx = $ua->get('/close/' => {Connection => 'close'});
ok !$tx->keep_alive, 'will not be kept alive';
ok $tx->kept_alive, 'was kept alive';
is $tx->res->code, 200, 'right status';
is $tx->res->headers->connection, 'close', 'right "Connection" value';
like $tx->res->body, qr/Mojo/, 'right content';
is $tx->res->body, 'Whatever!', 'right content';

# Second non keep alive request
$tx = $ua->get('/close/' => {Connection => 'close'});
ok !$tx->keep_alive, 'will not be kept alive';
ok !$tx->kept_alive, 'was not kept alive';
is $tx->res->code, 200, 'right status';
is $tx->res->headers->connection, 'close', 'right "Connection" value';
like $tx->res->body, qr/Mojo/, 'right content';
is $tx->res->body, 'Whatever!', 'right content';

# POST request
$tx = $ua->post('/fun/' => {Expect => 'fun'} => 'foo bar baz' x 128);
ok defined $tx->connection, 'has connection id';
is $tx->res->code, 200, 'right status';
like $tx->res->body, qr/Mojo/, 'right content';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Whatever!', 'right content';

# Parallel requests
my $delay = Mojo::IOLoop->delay;
Expand All @@ -166,13 +143,13 @@ $ua->post(
$ua->get('/parallel3/' => $delay->begin);
($tx, my $tx2, my $tx3) = $delay->wait;
ok $tx->is_finished, 'transaction is finished';
is $tx->res->body, 'Your Mojo is working!', 'right content';
is $tx->res->body, 'Whatever!', 'right content';
ok !$tx->error, 'no error';
ok $tx2->is_finished, 'transaction is finished';
is $tx2->res->body, 'Your Mojo is working!', 'right content';
is $tx2->res->body, 'Whatever!', 'right content';
ok !$tx2->error, 'no error';
ok $tx3->is_finished, 'transaction is finished';
is $tx3->res->body, 'Your Mojo is working!', 'right content';
is $tx3->res->body, 'Whatever!', 'right content';
ok !$tx3->error, 'no error';

# Form with chunked response
Expand All @@ -181,6 +158,7 @@ for my $i (1 .. 10) { $params{"test$i"} = $i }
my $result = '';
for my $key (sort keys %params) { $result .= $params{$key} }
my ($code, $body);
my $port = $ua->app_url->port;
$tx = $ua->post_form("http://127.0.0.1:$port/chunked" => \%params);
is $tx->res->code, 200, 'right status';
is $tx->res->body, $result, 'right content';
Expand All @@ -200,15 +178,47 @@ ok $local_port > 0, 'has local port';
ok $remote_address, 'has local address';
ok $remote_port > 0, 'has local port';

# Throttling
# Pipelined
$port = Mojo::IOLoop->generate_port;
my $daemon = Mojo::Server::Daemon->new(app => $app,
listen => ["http://127.0.0.1:$port"]);
my $daemon = Mojo::Server::Daemon->new(listen => ["http://127.0.0.1:$port"],
silent => 1);
$daemon->start;
is $daemon->app->moniker, 'HelloWorld', 'right moniker';
my $buffer = '';
my $id;
$id = Mojo::IOLoop->client(
{port => $port} => sub {
my ($loop, $err, $stream) = @_;
$stream->on(
read => sub {
my ($stream, $chunk) = @_;
$buffer .= $chunk;
Mojo::IOLoop->remove($id) and Mojo::IOLoop->stop
if $buffer =~ s/ is working!.*is working!$//gs;
}
);
$stream->write("GET /pipeline1/ HTTP/1.1\x0d\x0a"
. "Content-Length: 0\x0d\x0a\x0d\x0a"
. "GET /pipeline2/ HTTP/1.1\x0d\x0a"
. "Content-Length: 0\x0d\x0a\x0d\x0a");
}
);
Mojo::IOLoop->start;
like $buffer, qr/Mojo$/, 'transactions were pipelined';

# Throttling
$port = Mojo::IOLoop->generate_port;
$daemon = Mojo::Server::Daemon->new(
app => $app,
listen => ["http://127.0.0.1:$port"],
silent => 1
);
$daemon->start;
is $daemon->app->moniker, 'mojolicious', 'right moniker';
$tx = $ua->get("http://127.0.0.1:$port/throttle1" => {Connection => 'close'});
ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Your Mojo is working!', 'right content';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Whatever!', 'right content';
$daemon->stop;
$tx = $ua->inactivity_timeout(0.5)
->get("http://127.0.0.1:$port/throttle2" => {Connection => 'close'});
Expand All @@ -218,7 +228,7 @@ $daemon->start;
$tx = $ua->inactivity_timeout(10)
->get("http://127.0.0.1:$port/throttle3" => {Connection => 'close'});
ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Your Mojo is working!', 'right content';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Whatever!', 'right content';

done_testing();
14 changes: 10 additions & 4 deletions t/mojo/user_agent_tls.t
Expand Up @@ -26,8 +26,11 @@ app->log->level('fatal');
get '/' => {text => 'works!'};

# Web server with valid certificates
my $daemon
= Mojo::Server::Daemon->new(app => app, ioloop => Mojo::IOLoop->singleton);
my $daemon = Mojo::Server::Daemon->new(
app => app,
ioloop => Mojo::IOLoop->singleton,
silent => 1
);
my $port = Mojo::IOLoop->new->generate_port;
my $listen
= "https://127.0.0.1:$port"
Expand Down Expand Up @@ -116,8 +119,11 @@ ok !$tx->success, 'not successful';
ok $tx->error, 'has error';

# Web server with valid certificates and no verification
$daemon
= Mojo::Server::Daemon->new(app => app, ioloop => Mojo::IOLoop->singleton);
$daemon = Mojo::Server::Daemon->new(
app => app,
ioloop => Mojo::IOLoop->singleton,
silent => 1
);
$listen
= "https://127.0.0.1:$port"
. '?cert=t/mojo/certs/server.crt'
Expand Down
9 changes: 6 additions & 3 deletions t/mojo/websocket_proxy.t
Expand Up @@ -41,9 +41,12 @@ websocket '/test' => sub {
};

# HTTP server for testing
my $ua = Mojo::UserAgent->new;
my $daemon
= Mojo::Server::Daemon->new(app => app, ioloop => Mojo::IOLoop->singleton);
my $ua = Mojo::UserAgent->new;
my $daemon = Mojo::Server::Daemon->new(
app => app,
ioloop => Mojo::IOLoop->singleton,
silent => 1
);
my $port = Mojo::IOLoop->new->generate_port;
$daemon->listen(["http://127.0.0.1:$port"])->start;

Expand Down
7 changes: 5 additions & 2 deletions t/mojo/websocket_proxy_tls.t
Expand Up @@ -57,8 +57,11 @@ websocket '/test' => sub {
};

# Web server with valid certificates
my $daemon
= Mojo::Server::Daemon->new(app => app, ioloop => Mojo::IOLoop->singleton);
my $daemon = Mojo::Server::Daemon->new(
app => app,
ioloop => Mojo::IOLoop->singleton,
silent => 1
);
my $port = Mojo::IOLoop->new->generate_port;
my $listen
= "https://127.0.0.1:$port"
Expand Down

0 comments on commit ce256d3

Please sign in to comment.