-
-
Save cromedome/f98df8579a3877298d1df9ca165937a2 to your computer and use it in GitHub Desktop.
Dancer2 session stress testing
This file contains 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
#!/usr/bin/env perl | |
use 5.012; | |
use LWP::UserAgent; | |
use Test::More qw(no_plan); | |
my $ua = LWP::UserAgent->new( cookie_jar => {} ); | |
my $start_name = "Test$$"; | |
my $name = $start_name; | |
my $last_value = $name; | |
for(1..100) { | |
# For each outer iteration, clear our cookie jar so we get a new session | |
$ua->cookie_jar({}); | |
$ua->get("http://localhost:5000/its/$name"); | |
for (1..100) { | |
my $response = $ua->get("http://localhost:5000/hi"); | |
like($response->content, qr/Hi again, $name/, "Response greeted $name"); | |
} | |
# Same cookie jar, but change session content, and expect change to have | |
# taken on next iteration of fetches | |
$name = $start_name . time(); | |
$ua->get("http://localhost:5000/its/$name"); | |
for (1..100) { | |
my $response = $ua->get("http://localhost:5000/hi"); | |
like($response->content, qr/Hi again, $name/, "Response greeted $name"); | |
} | |
} |
This file contains 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
package testsessions; | |
use Dancer2; | |
our $VERSION = '0.1'; | |
get '/' => sub { | |
template 'index' => { 'title' => 'testsessions' }; | |
}; | |
get '/its/:name' => sub { | |
session name => route_parameters->{name}; | |
warn "Set name to " . route_parameters->{name}; | |
return "Hi there, " . session('name') . " (" . route_parameters->{name} . ")"; | |
}; | |
get '/hi' => sub { | |
my $name = session('name'); | |
if (!$name) { | |
warn "***** FAILED TO FETCH NAME *****"; | |
warn "session ID: " . session->id; | |
} | |
return "Hi again, " . session('name'); | |
}; | |
true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment