Debian Codegraph @

cpan/Memoize/t/st_concurrency

raw
1 #!/bin/sh
2
3 # running this script intermittently yields
4 #
5 # Magic number checking on storable file failed at ...
6 #
7 # but it is difficult to trigger this error 100% reliably
8 # as would be needed to turn this script into an actual test
9
10 perl -I. -x t/st_concurrency st_shared &
11 perl -I. -x t/st_concurrency st_shared &
12 perl -I. -x t/st_concurrency st_shared &
13 perl -I. -x t/st_concurrency st_shared &
14 wait && exec rm st_shared
15
16 #!perl
17 use strict; use warnings;
18
19 use Memoize::Storable;
20 use Fcntl 'LOCK_EX';
21
22 sub rand32 () { int rand 1<<32 }
23
24 # the script locks itself to increase the likelihood of the error:
25 # after releasing the lock, the first process writes to the file
26 # just as another process acquires the lock and starts to read it
27 # (but this still does not trigger the error reliably)
28
29 open my $fh, $0 or die $!;
30 flock $fh, LOCK_EX or die $!;
31
32 tie my %cache => 'Memoize::Storable', $ARGV[0];
33 $cache{(rand32)} = rand32;
34
35 close $fh;
36 # vim: ft=perl