File: 9.t

package info (click to toggle)
libcache-fastmmap-perl 1.60-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 356 kB
  • sloc: ansic: 1,404; perl: 635; makefile: 7
file content (82 lines) | stat: -rw-r--r-- 1,576 bytes parent folder | download | duplicates (5)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

#########################

use Test::More tests => 5;
BEGIN { use_ok('Cache::FastMmap') };
use Storable qw(freeze thaw);
use strict;

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

my $FC = Cache::FastMmap->new(
  page_size => 8192,
  num_pages => 3,
  init_file => 1,
  serializer => ''
);
ok( defined $FC );

sub rand_str {
  return join '', map { chr(rand(26) + ord('a')) } 1 .. int($_[0]);
}

srand(123);

my $Bad = 0;

my @LastEntries;
foreach my $i (1 .. 500) {
  my $K = rand_str(rand(10) + 10);
  my $V = rand_str(rand(20) + 20);

  $FC->set($K, $V);
  push @LastEntries, [ $K, $V ];
  shift @LastEntries if @LastEntries > 25;

  foreach my $e (0 .. @LastEntries-1) {
    local $_ = $LastEntries[$e];
    if ($_->[1] ne ($FC->get($_->[0]) || '')) {
      $Bad = 1;
      last;
    }
  }
  last if $Bad;
  select(undef, undef, undef, 0.01);
}

ok( !$Bad );

$FC = Cache::FastMmap->new(
  page_size => 8192,
  num_pages => 3,
  init_file => 1
);

ok( defined $FC );

$Bad = 0;
@LastEntries = ();

foreach my $i (1 .. 500) {
  my $K = rand_str(rand(10) + 10);
  my $V = [ rand_str(rand(20) + 20) ];

  $FC->set($K, $V);
  push @LastEntries, [ $K, freeze($V) ];
  shift @LastEntries if @LastEntries > 25;

  foreach my $e (0 .. @LastEntries-1) {
    local $_ = $LastEntries[$e];
    if ($_->[1] ne freeze($FC->get($_->[0]) || [])) {
      $Bad = 1;
      last;
    }
  }
  last if $Bad;
  select(undef, undef, undef, 0.01);
}

ok( !$Bad );