finalize session earlier
[catagits/Catalyst-Plugin-Session.git] / t / live_expiry_threshold.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9     eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
10       or plan skip_all =>
11       "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
12
13     eval {
14         require Test::WWW::Mechanize::Catalyst;
15         Test::WWW::Mechanize::Catalyst->VERSION(0.51);
16     }
17     or plan skip_all =>
18         'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test';
19 }
20
21 use lib "t/lib";
22 use Test::WWW::Mechanize::Catalyst "SessionExpiry";
23
24 my $ua = Test::WWW::Mechanize::Catalyst->new;
25
26 my $res = $ua->get( "http://localhost/session_data_expires" );
27 ok($res->is_success, "session_data_expires");
28
29 my $expiry = $res->decoded_content + 0;
30
31 $res = $ua->get( "http://localhost/session_expires" );
32 ok($res->is_success, "session_expires");
33 is($res->decoded_content, $expiry, "session_expires == session_data_expires");
34
35 sleep(1);
36
37 $res = $ua->get( "http://localhost/session_data_expires" );
38 ok($res->is_success, "session_data_expires");
39
40 is($res->decoded_content, $expiry, "expiration not updated");
41
42 $res = $ua->get( "http://localhost/session_expires" );
43 ok($res->is_success, "session_expires");
44 is($res->decoded_content, $expiry, "session_expires == session_data_expires");
45
46 #
47
48 $res = $ua->get( "http://localhost/update_session" );
49 ok($res->is_success, "update_session");
50
51 $res = $ua->get( "http://localhost/session_data_expires" );
52 ok($res->is_success, "session_data_expires");
53
54 my $updated = $res->decoded_content + 0;
55 ok($updated > $expiry, "expiration updated");
56
57 $expiry = $updated;
58
59 $res = $ua->get( "http://localhost/session_data_expires" );
60 ok($res->is_success, "session_data_expires");
61
62 is($res->decoded_content, $expiry, "expiration not updated");
63
64 $res = $ua->get( "http://localhost/session_expires" );
65 ok($res->is_success, "session_expires");
66 is($res->decoded_content, $expiry, "session_expires == session_data_expires");
67
68 sleep(10);
69
70 $res = $ua->get( "http://localhost/session_data_expires" );
71 ok($res->is_success, "session_data_expires");
72
73 $updated = $res->decoded_content + 0;
74 ok($updated > $expiry, "expiration updated");
75
76 $res = $ua->get( "http://localhost/session_expires" );
77 ok($res->is_success, "session_expires");
78 is($res->decoded_content, $updated, "session_expires == session_data_expires");
79
80
81 done_testing;