Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanCarloMachado committed May 29, 2014
8 parents 5e48a12 + 02e14e6 + e24be06 + 1cd130f + 2f4d84a + c5055d9 + b5302e2 + 9969a8b commit fb5d494
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/Storage/Adapter/CommonAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -300,6 +302,8 @@ public function testGetItemReturnsNullOnExpiredItem()
$ttl = $capabilities->getTtlPrecision();
$this->_options->setTtl($ttl);

$this->waitForFullSecond();

$this->_storage->setItem('key', 'value');

// wait until expired
Expand Down Expand Up @@ -543,6 +547,8 @@ public function testSetAndGetExpiredItem()
$ttl = $capabilities->getTtlPrecision();
$this->_options->setTtl($ttl);

$this->waitForFullSecond();

$this->_storage->setItem('key', 'value');

// wait until expired
Expand Down Expand Up @@ -581,6 +587,9 @@ public function testSetAndGetExpiredItems()
'key2' => 'value2',
'key3' => 'value3'
);

$this->waitForFullSecond();

$this->assertSame(array(), $this->_storage->setItems($items));

// wait until expired
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

0 comments on commit fb5d494

Please sign in to comment.