diff --git a/test/Storage/Adapter/CommonAdapterTest.php b/test/Storage/Adapter/CommonAdapterTest.php index 0f4003a85..6e98d8058 100644 --- a/test/Storage/Adapter/CommonAdapterTest.php +++ b/test/Storage/Adapter/CommonAdapterTest.php @@ -225,6 +225,8 @@ public function testHasItemReturnsFalseOnExpiredItem() $ttl = $capabilities->getTtlPrecision(); $this->_options->setTtl($ttl); + $this->waitForFullSecond(); + $this->assertTrue($this->_storage->setItem('key', 'value')); // wait until the item expired @@ -300,6 +302,8 @@ public function testGetItemReturnsNullOnExpiredItem() $ttl = $capabilities->getTtlPrecision(); $this->_options->setTtl($ttl); + $this->waitForFullSecond(); + $this->_storage->setItem('key', 'value'); // wait until expired @@ -543,6 +547,8 @@ public function testSetAndGetExpiredItem() $ttl = $capabilities->getTtlPrecision(); $this->_options->setTtl($ttl); + $this->waitForFullSecond(); + $this->_storage->setItem('key', 'value'); // wait until expired @@ -581,6 +587,9 @@ public function testSetAndGetExpiredItems() 'key2' => 'value2', 'key3' => 'value3' ); + + $this->waitForFullSecond(); + $this->assertSame(array(), $this->_storage->setItems($items)); // wait until expired @@ -828,6 +837,8 @@ public function testTouchItem() $this->_options->setTtl(2 * $capabilities->getTtlPrecision()); + $this->waitForFullSecond(); + $this->assertTrue($this->_storage->setItem('key', 'value')); // sleep 1 times before expire to touch the item @@ -1000,6 +1011,8 @@ public function testClearExpired() $ttl = $capabilities->getTtlPrecision(); $this->_options->setTtl($ttl); + $this->waitForFullSecond(); + $this->assertTrue($this->_storage->setItem('key1', 'value1')); // wait until the first item expired @@ -1090,4 +1103,14 @@ public function testGetAvailableSpace() $this->assertLessThanOrEqual($totalSpace, $availableSpace); } } + + /** + * This will wait for a full second started + * to reduce test failures on high load servers + * @see https://github.com/zendframework/zf2/issues/5144 + */ + protected function waitForFullSecond() + { + usleep((microtime(true)-time()) * 1000000); + } }