Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (34 sloc) 1.04 KB
use strict;
use warnings;
use Test::More;
use Parallel::ForkManager;
use BerkeleyDB;
use FindBin qw/$Bin/;
use Data::Dumper;
use File::Spec;
my $pm = new Parallel::ForkManager(4);
my $tmp_dir = File::Spec->tmpdir();
my $env = new BerkeleyDB::Env
-Home => $tmp_dir,
or die "cannot open environment: $BerkeleyDB::Error\n";
my $berkeleydb_temp_file = "$Bin/tmp.berkeleydb"; # temp file for BerkeleyDB
unlink($berkeleydb_temp_file) if -e $berkeleydb_temp_file;
my $db = tie my %data, 'BerkeleyDB::Hash',
-Filename => $berkeleydb_temp_file,
-Flags => DB_CREATE,
-Env => $env
or die "Cannot create file: $! $BerkeleyDB::Error\n";
foreach my $i (1 .. 1000) {
$pm->start and next; # do the fork
my $lock = $db->cds_lock();
$data{$i} = $i * 2;
$pm->finish; # Terminates the child process
is(scalar(keys %data), 1000);