#42311 [Opn]: Intermittent failure of test bug35885.phpt

From: Date: Wed, 15 Aug 2007 13:53:17 +0000
Subject: #42311 [Opn]: Intermittent failure of test bug35885.phpt
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116116@lists.php.net to get a copy of this message
ID: 42311 User updated by: robin_fernandes at uk dot ibm dot com Reported By: robin_fernandes at uk dot ibm dot com Status: Open Bug Type: Date/time related Operating System: Windows PHP Version: 5.2.3 New Comment: Below is a suggested patch which modifies the test to allow for a 1 second margin between the timestamps. I have confirmed the resulting test passes consistently on Windows on PHP 5.2.3, but have done no further testing. Index: C:/php5-latest-phpt/ext/date/tests/bug35885.phpt =================================================================== --- C:/php5-latest-phpt/ext/date/tests/bug35885.phpt (revision 13029) +++ C:/php5-latest-phpt/ext/date/tests/bug35885.phpt (working copy) @@ -4,15 +4,15 @@ <?php date_default_timezone_set("UTC"); -$ts = date(DATE_ISO8601, strtotime('NOW')); -$ts2 = date(DATE_ISO8601, time()); +$ts = strtotime('NOW'); +$ts2 = time(); -$res = ($ts == $ts2); +$res = ($ts == $ts2) || ($ts == $ts2-1); var_dump($res); if (!$res) { - var_dump($ts); - var_dump($ts2); + var_dump(date(DATE_ISO8601, $ts)); + var_dump(date(DATE_ISO8601, $ts2)); } ?> Previous Comments: ------------------------------------------------------------------------ [2007-08-15 13:48:21] robin_fernandes at uk dot ibm dot com Description: ------------ Test http://lxr.php.net/source/php-src/ext/date/tests/bug35885.phpt compares two time stamps representing the current time. However, these timestamps are seized in separate statements. The comparison fails intermittently, because the seconds occasionally tick over between the two calls. Below is bug35885.phpt enclosed in a loop to prove that it fails intermittently. It will break out of the loop on failure. Expected time to failure is less than 10 seconds. Reproduce code: --------------- <?php date_default_timezone_set("UTC"); while (true) { $ts = date(DATE_ISO8601, strtotime('NOW')); $ts2 = date(DATE_ISO8601, time()); $res = ($ts == $ts2); var_dump($res); if (!$res) { var_dump($ts); var_dump($ts2); break; } } ?> Expected result: ---------------- N/A (loop) Actual result: -------------- bool(true) bool(true) [...] bool(true) bool(false) string(24) "2007-08-15T13:26:05+0000" string(24) "2007-08-15T13:26:06+0000" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42311&edit=1

« previous php.bugs (#116116) next »