Skip to content

Commit

Permalink
fixes zendframework#5144: Cache TTL-Tests: wait for full second befor…
Browse files Browse the repository at this point in the history
…e start TTL tests
  • Loading branch information
marc-mabe committed May 20, 2014
1 parent 369afb5 commit d81384d
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 d81384d

Please sign in to comment.