[ticket/12996] Fix reliability issue in flock test.

$delta was always an int - so, this test would sometimes fail if you
happened to call time() /very/ close to a 1s boundary.

Found by HHVM's continuous testing.

PHPBB3-12996
This commit is contained in:
Fred Emmott 2014-08-18 17:35:12 -07:00 committed by Andreas Fischer
parent a82a88b555
commit 0ef7a9d455

View file

@ -83,9 +83,9 @@ class phpbb_lock_flock_test extends phpbb_test_case
sleep(1);
$lock = new \phpbb\lock\flock($path);
$start = time();
$start = microtime(true);
$ok = $lock->acquire();
$delta = time() - $start;
$delta = microtime(true) - $start;
$this->assertTrue($ok);
$this->assertTrue($lock->owns_lock());
$this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon');
@ -94,9 +94,9 @@ class phpbb_lock_flock_test extends phpbb_test_case
$this->assertFalse($lock->owns_lock());
// acquire again, this should be instantaneous
$start = time();
$start = microtime(true);
$ok = $lock->acquire();
$delta = time() - $start;
$delta = microtime(true) - $start;
$this->assertTrue($ok);
$this->assertTrue($lock->owns_lock());
$this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously');