[perl-Cache-Cache] Fix time races in tests

Petr Pisar ppisar at fedoraproject.org
Thu Jun 26 13:05:48 UTC 2014


commit fcebe9f86bec7e6e6e6bead150085f3684eaddbf
Author: Petr Písař <ppisar at redhat.com>
Date:   Thu Jun 26 14:52:12 2014 +0200

    Fix time races in tests

 ...che-1.06-Make-tests-aware-of-running-time.patch |  119 ++++++++++++++++++++
 perl-Cache-Cache.spec                              |    8 +-
 2 files changed, 126 insertions(+), 1 deletions(-)
---
diff --git a/Cache-Cache-1.06-Make-tests-aware-of-running-time.patch b/Cache-Cache-1.06-Make-tests-aware-of-running-time.patch
new file mode 100644
index 0000000..de8900d
--- /dev/null
+++ b/Cache-Cache-1.06-Make-tests-aware-of-running-time.patch
@@ -0,0 +1,119 @@
+From 79b3decdb39c6a12261bb9a5f5bbada5ceec39eb Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar at redhat.com>
+Date: Thu, 26 Jun 2014 13:43:09 +0200
+Subject: [PATCH] Make tests aware of running time
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Some tests could fail if they run slower then the tested time limits
+because then caches entries expired on different place expected. This
+patch skips such tests if the running time is not shorter than
+expected.
+
+CPAN RT#88418
+
+Signed-off-by: Petr Písař <ppisar at redhat.com>
+---
+ lib/Cache/CacheTester.pm          | 30 ++++++++++++++++++++++++------
+ lib/Cache/SizeAwareCacheTester.pm | 10 ++++++++--
+ 2 files changed, 32 insertions(+), 8 deletions(-)
+
+diff --git a/lib/Cache/CacheTester.pm b/lib/Cache/CacheTester.pm
+index 8f64577..1cd6f82 100644
+--- a/lib/Cache/CacheTester.pm
++++ b/lib/Cache/CacheTester.pm
+@@ -168,12 +168,18 @@ sub _test_four
+ 
+   my $value = 'Test Value';
+ 
++  my $start = time;
+   $cache->set( $key, $value, $expires_in );
+ 
+   my $fetched_value = $cache->get( $key );
+ 
+-  ( $fetched_value eq $value ) ?
+-    $self->ok( ) : $self->not_ok( '$fetched_value eq $value' );
++  if (time - $start < $expires_in) {
++    ( $fetched_value eq $value ) ?
++      $self->ok( ) : $self->not_ok( '$fetched_value eq $value' );
++  } else {
++      $self->skip( '$fetched_value eq $value (not finished in ' .
++        $expires_in . ' s)' );
++  }
+ 
+   sleep( $EXPIRES_DELAY + 1 );
+ 
+@@ -460,12 +466,18 @@ sub _test_thirteen
+ 
+   my $value = 'Test Value';
+ 
++  my $start = time;
+   $cache->set( $key, $value, $expires_in );
+ 
+   my $fetched_value = $cache->get( $key );
+ 
+-  ( $fetched_value eq $value ) ?
+-    $self->ok( ) : $self->not_ok( '$fetched_value eq $value' );
++  if (time - $start < $expires_in) {
++    ( $fetched_value eq $value ) ?
++      $self->ok( ) : $self->not_ok( '$fetched_value eq $value' );
++  } else {
++    $self->skip( '$fetched_value eq $value (not finished in ' .
++      $expires_in . ' s)' );
++  }
+ 
+   sleep( $EXPIRES_DELAY + 1 );
+ 
+@@ -525,12 +537,18 @@ sub _test_fifteen
+ 
+   my $value = 'Test Value';
+ 
++  my $start = time;
+   $cache->set( $key, $value, $expires_in );
+ 
+   my $fetched_value = $cache->get( $key );
+ 
+-  ( $fetched_value eq $value ) ?
+-    $self->ok( ) : $self->not_ok( '$fetched_value eq $value' );
++  if (time - $start < $expires_in) {
++    ( $fetched_value eq $value ) ?
++      $self->ok( ) : $self->not_ok( '$fetched_value eq $value' );
++  } else {
++      $self->skip( '$fetched_value eq $value (not finished in ' .
++        $expires_in . ' s)' );
++  }
+ 
+   sleep( $EXPIRES_DELAY + 1 );
+ 
+diff --git a/lib/Cache/SizeAwareCacheTester.pm b/lib/Cache/SizeAwareCacheTester.pm
+index 1a660f7..1a36c48 100644
+--- a/lib/Cache/SizeAwareCacheTester.pm
++++ b/lib/Cache/SizeAwareCacheTester.pm
+@@ -110,6 +110,7 @@ sub _test_two
+ 
+   my $first_expires_in = 20;
+ 
++  my $start = time;
+   $cache->set( $first_key, $value, $first_expires_in );
+ 
+   my $first_size = $cache->size( );
+@@ -146,8 +147,13 @@ sub _test_two
+ 
+   my $first_value = $cache->get( $first_key );
+ 
+-  ( $first_value eq $value ) ?
+-    $self->ok( ) : $self->not_ok( '$first_value eq $value' );
++  if (time - $start < $first_expires_in ) {
++    ( $first_value eq $value ) ?
++      $self->ok( ) : $self->not_ok( '$first_value eq $value' );
++  } else {
++    $self->skip( '$first_value eq $value (not finished in ' .
++      $first_expires_in . ' s)');
++  }
+ 
+ }
+ 
+-- 
+1.9.3
+
diff --git a/perl-Cache-Cache.spec b/perl-Cache-Cache.spec
index e964f41..d17ba8e 100644
--- a/perl-Cache-Cache.spec
+++ b/perl-Cache-Cache.spec
@@ -1,11 +1,13 @@
 Name:           perl-Cache-Cache
 Version:        1.06
-Release:        15%{?dist}
+Release:        16%{?dist}
 Summary:        Generic cache interface and implementations
 License:        GPL+ or Artistic
 Group:          Development/Libraries
 URL:            http://search.cpan.org/dist/Cache-Cache/
 Source0:        http://www.cpan.org/authors/id/J/JS/JSWARTZ/Cache-Cache-%{version}.tar.gz
+# Fix time races in tests, bug #1112553, CPAN RT#88418
+Patch0:         Cache-Cache-1.06-Make-tests-aware-of-running-time.patch
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildArch:      noarch
 BuildRequires:  perl(Digest::SHA1) >= 2.02
@@ -27,6 +29,7 @@ of the filesystem or shared memory.
 
 %prep
 %setup -q -n Cache-Cache-%{version}
+%patch0 -p1
 
 %build
 %{__perl} Makefile.PL INSTALLDIRS=vendor
@@ -55,6 +58,9 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man3/*
 
 %changelog
+* Thu Jun 26 2014 Petr Pisar <ppisar at redhat.com> - 1.06-16
+- Fix time races in tests (bug #1112553)
+
 * Sat Jun 07 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.06-15
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild
 


More information about the scm-commits mailing list