Add tests for counter.
authorMike Taylor <mike@indexdata.com>
Mon, 8 Dec 2014 16:56:40 +0000 (16:56 +0000)
committerMike Taylor <mike@indexdata.com>
Mon, 8 Dec 2014 16:56:40 +0000 (16:56 +0000)
t/02-IndexData-Utils-PersistentCounter.t

index 491bc7d..d6930dc 100644 (file)
@@ -1,5 +1,26 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 15;
 BEGIN { use_ok('IndexData::Utils::PersistentCounter') };
+
+my $file = "/tmp/id-u-pc-$$";
+my $counter = new IndexData::Utils::PersistentCounter($file);
+ok(!defined $counter, "can't open non-existent counter");
+
+$counter = new IndexData::Utils::PersistentCounter("/x/$file", 1);
+ok(!defined $counter, "can't create counter in silly place");
+
+$counter = new IndexData::Utils::PersistentCounter($file, 1);
+ok(defined $counter, "created new counter: $!");
+
+foreach my $i (1..10) {
+    my $n = $counter->next();
+    is($n, $i);
+}
+
+### should test access from multiple processes
+
+$counter->delete();
+$counter = new IndexData::Utils::PersistentCounter($file);
+ok(!defined $counter, "can't open deleted counter");