From 3cebc8759a22692c37061ef7866545fa7fe7d516 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 6 Nov 2012 23:45:19 +0000 Subject: [PATCH] test: expose try_for() as a common test function This saves us from reinventing it in every test and will help us detect stuck tests more easily. --- lib/MogileFS/Test.pm | 11 ++++++++++- t/00-startup.t | 9 --------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/MogileFS/Test.pm b/lib/MogileFS/Test.pm index 7019427..4270268 100644 --- a/lib/MogileFS/Test.pm +++ b/lib/MogileFS/Test.pm @@ -9,7 +9,7 @@ use IO::Socket::INET; use MogileFS::Server; use base 'Exporter'; -our @EXPORT = qw(&find_mogclient_or_skip &temp_store &create_mogstored &create_temp_tracker); +our @EXPORT = qw(&find_mogclient_or_skip &temp_store &create_mogstored &create_temp_tracker &try_for); sub find_mogclient_or_skip { @@ -152,6 +152,15 @@ sub create_mogstored { return undef; } +sub try_for { + my ($tries, $code) = @_; + for (1..$tries) { + return 1 if $code->(); + sleep 1; + } + return 0; +} + ############################################################################ package ProcessHandle; sub new { diff --git a/t/00-startup.t b/t/00-startup.t index d602b5c..263a185 100644 --- a/t/00-startup.t +++ b/t/00-startup.t @@ -392,13 +392,4 @@ foreach my $t (qw(file file_on file_to_delete)) { is($info->{fid}, $opts->{fid}, "explicit fid is correctly set"); } -sub try_for { - my ($tries, $code) = @_; - for (1..$tries) { - return 1 if $code->(); - sleep 1; - } - return 0; -} - done_testing(); -- 2.11.4.GIT