File: session_object.t

package info (click to toggle)
libdancer2-perl 0.152000%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,820 kB
  • ctags: 536
  • sloc: perl: 8,034; sh: 51; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# session_object.t

use strict;
use warnings;
use Test::More;
use Test::Fatal;

use Dancer2::Core::Session;
use Dancer2::Session::Simple;
use Class::Load 'try_load_class';

my $ENGINE = Dancer2::Session::Simple->new;

my $CPRNG_AVAIL = try_load_class('Math::Random::ISAAC::XS')
  && try_load_class('Crypt::URandom');

diag $CPRNG_AVAIL
  ? "Crypto strength tokens"
  : "Default strength tokens";

subtest 'session attributes' => sub {
    my $s1 = $ENGINE->create;

    my $id = $s1->id;
    ok defined($id), 'id is defined';
    is(exception { $s1->id("new_$id") }, undef, 'id can be set');
    is($s1->id, "new_$id", '... new value found for id');

    my $s2 = $ENGINE->create;
    isnt($s1->id, $s2->id, "IDs are not the same");
};

my $count = 10_000;
subtest "$count session IDs and no dups" => sub {
    my $seen      = {};
    my $iteration = 0;
    foreach my $i (1 .. $count) {
        my $s1 = $ENGINE->create;
        my $id = $s1->id;
        if (exists $seen->{$id}) {
            last;
        }
        $seen->{$id} = 1;
        $iteration++;
    }

    is $iteration, $count,
      "no duplicate ID after $count iterations (done $iteration)";
};

done_testing;