From 9ac991636e1eeace39f46a01ba34e8ddf2adadd9 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Mon, 22 Nov 2010 02:02:11 +0000 Subject: [PATCH] MINOR Merged r113933,113936-113937 from branches/2.4 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114001 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- tests/model/DbDatetimeTest.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/model/DbDatetimeTest.php b/tests/model/DbDatetimeTest.php index ee1132a0f..5d189a823 100644 --- a/tests/model/DbDatetimeTest.php +++ b/tests/model/DbDatetimeTest.php @@ -1,19 +1,26 @@ 1800, + E_USER_NOTICE => 5, + ); /** * Check if dates match more or less. This takes into the account the db query * can overflow to the next second giving offset readings. */ private function matchesRoughly($date1, $date2, $comment = '') { - $allowedDifference = 15; // seconds + $allowedDifference = 5 + abs(self::$offset); // seconds $time1 = is_numeric($date1) ? $date1 : strtotime($date1); $time2 = is_numeric($date2) ? $date2 : strtotime($date2); - $this->assertTrue(abs($time1-$time2)<$allowedDifference, $comment . " ($date1, $date2)"); + $this->assertTrue(abs($time1-$time2)<$allowedDifference, $comment . " (times differ by " . abs($time1-$time2) . " seconds)"); } private function getDbNow() { @@ -21,6 +28,22 @@ class DbDatetimeTest extends FunctionalTest { return DB::query($query)->value(); } + function setUpOnce() { + parent::setUpOnce(); + + self::$offset = time() - strtotime(DB::query('SELECT ' . DB::getConn()->now())->value()); + foreach(self::$offset_thresholds as $code => $offset) { + if(abs(self::$offset) > $offset) { + if($code == E_USER_NOTICE) { + Debug::show('The time of the database is out of sync with the webserver by ' . abs(self::$offset) . ' seconds.'); + } else { + trigger_error('The time of the database is out of sync with the webserver by ' . abs(self::$offset) . ' seconds.', $code); + } + break; + } + } + } + function setUp() { parent::setUp(); $this->adapter = DB::getConn();