Skip to content

Commit

Permalink
Merge branch 'hotfix/zendframework#6303-fix-zendframework#5144-ttl-te…
Browse files Browse the repository at this point in the history
…sts-stability'

Close zendframework#6303
Close zendframework#5144
  • Loading branch information
Ocramius committed May 20, 2014
2 parents 42ad2cc + e2481f4 commit 3f870db
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/ZendTest/Cache/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 3f870db

Please sign in to comment.