projects
/
perl-indexdata-utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
299a16a
)
Add concurrency testing from three processes.
author
Mike Taylor
<mike@indexdata.com>
Tue, 9 Dec 2014 12:11:44 +0000
(12:11 +0000)
committer
Mike Taylor
<mike@indexdata.com>
Tue, 9 Dec 2014 12:11:44 +0000
(12:11 +0000)
t/02-IndexData-Utils-PersistentCounter.t
patch
|
blob
|
history
diff --git
a/t/02-IndexData-Utils-PersistentCounter.t
b/t/02-IndexData-Utils-PersistentCounter.t
index
a7752d6
..
aa05060
100644
(file)
--- a/
t/02-IndexData-Utils-PersistentCounter.t
+++ b/
t/02-IndexData-Utils-PersistentCounter.t
@@
-1,7
+1,7
@@
use strict;
use warnings;
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More tests => 17;
BEGIN { use_ok('IndexData::Utils::PersistentCounter') };
my $file = "/tmp/id-u-pc-$$";
BEGIN { use_ok('IndexData::Utils::PersistentCounter') };
my $file = "/tmp/id-u-pc-$$";
@@
-21,7
+21,27
@@
foreach my $i (1..5) {
ok($n == $i, "n has correct value $i");
}
ok($n == $i, "n has correct value $i");
}
-### should test access from multiple processes
+# Three processes making five accesses each
+for (my $i = 0; $i < 3; $i ++) {
+ my $pid = fork();
+ if ($pid == 0) {
+ # child
+ foreach my $j (1..5) {
+ my $n = $counter->next();
+ print "# child ", $i+1, ", access ", $j+1, ": value is $n\n";
+ }
+ exit 0;
+ } else {
+ print "# process $pid started\n";
+ }
+}
+
+while ((my $pid = wait()) > 0) {
+ print "# process $pid completed\n";
+}
+
+my $n = $counter->next();
+ok($n == 20, "n == 20 after 20 accesses (n=$n)");
my $ok = $counter->delete();
ok($ok, "deleted counter file");
my $ok = $counter->delete();
ok($ok, "deleted counter file");