Skip to content

Instantly share code, notes, and snippets.

@yko
Created January 23, 2011 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yko/792088 to your computer and use it in GitHub Desktop.
Save yko/792088 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
# Disable epoll and kqueue
BEGIN { $ENV{MOJO_POLL} = 1 }
use Test::More tests => 10;
use Mojolicious::Lite;
use Test::Mojo;
use Mojo::Cookie::Response;
use Mojo::Util qw/b64_decode b64_encode/;
use Storable qw/freeze thaw/;
app->secret('Mojolicious rocks!');
my $delayed_render;
get '/' => sub {
my $c = shift;
$c->session("mojolicious" => "rocks!");
$c->render_text('Simple response');
};
get '/delayed' => sub {
my $c = shift;
$c->session("mojolicious" => "rocks! (async)");
$c->render_later;
$delayed_render = $c;
};
my $client = app->client;
my $t = Test::Mojo->new;
# Simple response
$t->get_ok('/')->text_is('Simple response');
ok my $cookie = $t->tx->res->cookie('mojolicious');
ok my $value = $cookie->value;
b64_decode $value;
my $session = thaw $value;
is $session->{mojolicious}, 'rocks!';
# Delayed response
# Client timer
$client->ioloop->timer(
'0.1' => sub {
$delayed_render->render_text("Delayed response");
}
);
$t->get_ok('/delayed')->text_is('Delayed response');
ok $cookie = $t->tx->res->cookie('mojolicious');
ok $value = $cookie->value;
b64_decode $value;
$session = thaw $value;
is $session->{mojolicious}, 'rocks! (async)';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment