Skip Menu |

This queue is for tickets about the Plucene CPAN distribution.

Report information
The Basics
Id: 17371
Status: new
Priority: 0/
Queue: Plucene

People
Owner: Nobody in particular
Requestors: plucene [...] wormbytes.ca
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.24
Fixed in: (no value)



Subject: Added unit test for Plucene::Utils. Croak if obtaining lock failed.
The unit test works both the successful lock acquisition, and also what happens if obtaining the lock fails. Updated the do_lock() function to _croak_ if the lock could not be obtained, rather than simply warning and then running the function anyway.
Subject: 20060130-utils.patch
# HG changeset patch # User Robert James Kaes <rjk@wormbytes.ca> # Node ID de0e94fcab03762ba26d6041c704c1a926e1d098 # Parent a6393cd12829878da54a8c73b88d12106bf8e8c8 Added unit test for Plucene::Utils. Croak if obtaining lock failed. The unit test works both the successful lock acquisition, and also what happens if obtaining the lock fails. Updated the do_lock() function to _croak_ if the lock could not be obtained, rather than simply warning and then running the function anyway. diff -r a6393cd12829 -r de0e94fcab03 lib/Plucene/Utils.pm --- a/lib/Plucene/Utils.pm Wed Jan 25 19:38:30 2006 -0500 +++ b/lib/Plucene/Utils.pm Wed Jan 25 21:05:28 2006 -0500 @@ -42,7 +42,7 @@ sub do_locked (&$) { sleep 1; warn "I had to sleep to get a lock on $lock"; } - carp "Couldn't get lock $lock: $!"; + croak "Couldn't get lock $lock: $!"; got_lock: $sub->(); close *FH; diff -r a6393cd12829 -r de0e94fcab03 t/utils.t --- /dev/null Thu Jan 1 00:00:00 1970 +0000 +++ b/t/utils.t Wed Jan 25 21:05:28 2006 -0500 @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# +# Test the Plucene::Utils module. +# +# Author: Robert James Kaes <rjk@wormbytes.ca> +# + +use strict; +use warnings; + +use Test::More tests => 4; +use Test::Exception; + +use File::Temp qw(tempfile); + +BEGIN { + use_ok('Plucene::Utils'); +} + +# Check the log by running the function supplied +my $locked_func_ran = 0; +sub run_lock_function { $locked_func_ran = 1; } + +do_locked( + \&run_lock_function, + File::Temp::tempnam("/tmp", "plucene.lock"), +); +ok($locked_func_ran == 1, "Locked function ran successfully"); + +$locked_func_ran = 0; +my $fh = File::Temp->new(); +throws_ok { + do_locked( + \&run_lock_function, + $fh->filename, + ); +} qr/Couldn't get lock/, "Correctly died trying to grab existing lock"; +ok($locked_func_ran == 0, "Locked not received, so function not run"); + +# vim: filetype=perl