From 452e4301773f3ed690f7081d113a22087a5eef9c Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 8 Dec 2014 16:56:40 +0000 Subject: [PATCH] Add tests for counter. --- t/02-IndexData-Utils-PersistentCounter.t | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/t/02-IndexData-Utils-PersistentCounter.t b/t/02-IndexData-Utils-PersistentCounter.t index 491bc7d..d6930dc 100644 --- a/t/02-IndexData-Utils-PersistentCounter.t +++ b/t/02-IndexData-Utils-PersistentCounter.t @@ -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"); -- 1.7.10.4