Patch Fix-uniqid-tests-for-Windows-platforms for Testing related Bug #66280
Patch version 2013-12-12 22:16 UTC
Return to Bug #66280 |
Download this patch
Patch Revisions:
Developer: ericsten@php.net
From d744bdea98ff8023c1d4b7a096280ed6c3096fa9 Mon Sep 17 00:00:00 2001
From: Eric Stenson <ericsten@php.net>
Date: Wed, 27 Nov 2013 09:35:21 -0800
Subject: [PATCH 2/2] Fix uniqid tests for Windows platforms
On Windows boxes, the microtime precision is not granular enough
to reliably register a difference if two calls to uniqid() are made
concurrently. This is a fix to the uniqid() test to avoid the false
positive when run on Windows machines. Also, added a test to exercise
the 'more_entropy' variant of uniqid().
---
tests/strings/001.phpt | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/tests/strings/001.phpt b/tests/strings/001.phpt
index 7b61835..98ceceb 100644
--- a/tests/strings/001.phpt
+++ b/tests/strings/001.phpt
@@ -177,11 +177,23 @@ if ($ss == "\$'") {
}
-echo "Testing uniqid: ";
+echo "Testing uniqid(true): ";
+$str = "prefix";
+$ui1 = uniqid($str, true);
+$ui2 = uniqid($str, true);
+
+$len = 29;
+
+if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) {
+ echo("passed\n");
+} else {
+ echo("failed!\n");
+}
+
+echo "Testing uniqid(false): ";
$str = "prefix";
$ui1 = uniqid($str);
-/* Must sleep here to let uniqid generate a different unique ID */
-usleep( 10 );
+usleep( 1 );
$ui2 = uniqid($str);
$len = strncasecmp(PHP_OS, 'CYGWIN', 6) ? 19 : 29;
@@ -209,4 +221,5 @@ Testing ufirst: passed
Testing strtr: passed
Testing addslashes: passed
Testing stripslashes: passed
-Testing uniqid: passed
+Testing uniqid(true): passed
+Testing uniqid(false): passed
--
1.7.10.msysgit.1
|