b8c914
From 8985b12868f07d9ef501580d600e49fe8f230eb4 Mon Sep 17 00:00:00 2001
b8c914
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
b8c914
Date: Tue, 22 Aug 2017 09:49:42 +0200
b8c914
Subject: [PATCH] Time-HiRes: Fix unreliable t/usleep.t and t/utime.t
b8c914
MIME-Version: 1.0
b8c914
Content-Type: text/plain; charset=UTF-8
b8c914
Content-Transfer-Encoding: 8bit
b8c914
b8c914
Ported from Time-HiRes-1.9746.
b8c914
b8c914
The tests randomly failed on loaded machines because a CPU scheduler
b8c914
could add unpredictable delays.
b8c914
b8c914
CPAN RT#122819
b8c914
b8c914
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8c914
---
b8c914
 dist/Time-HiRes/t/usleep.t | 4 ++--
b8c914
 dist/Time-HiRes/t/utime.t  | 9 +++++----
b8c914
 2 files changed, 7 insertions(+), 6 deletions(-)
b8c914
b8c914
diff --git a/dist/Time-HiRes/t/usleep.t b/dist/Time-HiRes/t/usleep.t
b8c914
index 9322458..bb66cbe 100644
b8c914
--- a/dist/Time-HiRes/t/usleep.t
b8c914
+++ b/dist/Time-HiRes/t/usleep.t
b8c914
@@ -32,7 +32,7 @@ SKIP: {
b8c914
     Time::HiRes::usleep(500_000);
b8c914
     my $f2 = Time::HiRes::time();
b8c914
     my $d = $f2 - $f;
b8c914
-    ok $d > 0.4 && $d < 0.9 or print("# slept $d secs $f to $f2\n");
b8c914
+    ok $d > 0.49 or print("# slept $d secs $f to $f2\n");
b8c914
 }
b8c914
 
b8c914
 SKIP: {
b8c914
@@ -40,7 +40,7 @@ SKIP: {
b8c914
     my $r = [ Time::HiRes::gettimeofday() ];
b8c914
     Time::HiRes::sleep( 0.5 );
b8c914
     my $f = Time::HiRes::tv_interval $r;
b8c914
-    ok $f > 0.4 && $f < 0.9 or print("# slept $f instead of 0.5 secs.\n");
b8c914
+    ok $f > 0.49 or print("# slept $f instead of 0.5 secs.\n");
b8c914
 }
b8c914
 
b8c914
 SKIP: {
b8c914
diff --git a/dist/Time-HiRes/t/utime.t b/dist/Time-HiRes/t/utime.t
b8c914
index 22fd48e..c5c7e55 100644
b8c914
--- a/dist/Time-HiRes/t/utime.t
b8c914
+++ b/dist/Time-HiRes/t/utime.t
b8c914
@@ -106,17 +106,18 @@ print "# utime undef sets time to now\n";
b8c914
 	my ($fh2, $filename2) = tempfile( "Time-HiRes-utime-XXXXXXXXX", UNLINK => 1 );
b8c914
 
b8c914
 	my $now = Time::HiRes::time;
b8c914
+	 sleep(1);
b8c914
 	is Time::HiRes::utime(undef, undef, $filename1, $fh2), 2, "Two files changed";
b8c914
 
b8c914
 	{
b8c914
 		my ($got_atime, $got_mtime) = ( Time::HiRes::stat($fh1) )[8, 9];
b8c914
-		cmp_ok abs( $got_atime - $now), '<', 0.1, "File 1 atime set correctly";
b8c914
-		cmp_ok abs( $got_mtime - $now), '<', 0.1, "File 1 mtime set correctly";
b8c914
+		cmp_ok $got_atime, '>=', $now, "File 1 atime set correctly";
b8c914
+		cmp_ok $got_mtime, '>=', $now, "File 1 mtime set correctly";
b8c914
 	}
b8c914
 	{
b8c914
 		my ($got_atime, $got_mtime) = ( Time::HiRes::stat($filename2) )[8, 9];
b8c914
-		cmp_ok abs( $got_atime - $now), '<', 0.1, "File 2 atime set correctly";
b8c914
-		cmp_ok abs( $got_mtime - $now), '<', 0.1, "File 2 mtime set correctly";
b8c914
+		cmp_ok $got_atime, '>=', $now, "File 2 atime set correctly";
b8c914
+		cmp_ok $got_mtime, '>=', $now, "File 2 mtime set correctly";
b8c914
 	}
b8c914
 };
b8c914
 
b8c914
-- 
b8c914
2.9.5
b8c914