php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42311 Intermittent failure of test bug35885.phpt
Submitted: 2007-08-15 13:48 UTC Modified: 2008-11-10 01:00 UTC
From: robin_fernandes at uk dot ibm dot com Assigned: derick (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.2.3 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: robin_fernandes at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-08-15 13:48 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-15 13:53 UTC] robin_fernandes at uk dot ibm dot com
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));
 }
 
 ?>
 [2007-08-16 06:39 UTC] jani@php.net
Assigned to the ext/date maintainer.
 [2008-11-02 12:59 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-11-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC