Skip to content

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6575-redis-setitems-…
Browse files Browse the repository at this point in the history
…last-item-overwritten-fixes-zendframework/zf2#6324' into develop

Close zendframework/zendframework#6575
Close zendframework/zendframework#6324
Forward port zendframework/zendframework#6575
Forward port zendframework/zendframework#6324
  • Loading branch information
Ocramius committed Nov 22, 2014
2 parents 0b10864 + 0d3c969 commit e59ada6
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions CommonAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,36 +583,55 @@ public function testSetAndGetExpiredItems()
$this->markTestSkipped("Adapter doesn't support item expiration");
}

$ttl = $capabilities->getTtlPrecision();
$this->_options->setTtl($ttl);

$items = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
// item definition
$itemsHigh = array(
'keyHigh1' => 'valueHigh1',
'keyHigh2' => 'valueHigh2',
'keyHigh3' => 'valueHigh3'
);
$itemsLow = array(
'keyLow1' => 'valueLow1',
'keyLow2' => 'valueLow2',
'keyLow3' => 'valueLow3'
);
$items = $itemsHigh + $itemsLow;

$this->waitForFullSecond();
// set items with high TTL
$this->_options->setTtl(123456);
$this->assertSame(array(), $this->_storage->setItems($itemsHigh));

$this->assertSame(array(), $this->_storage->setItems($items));
// set items with low TTL
$ttl = $capabilities->getTtlPrecision();
$this->_options->setTtl($ttl);
$this->waitForFullSecond();
$this->assertSame(array(), $this->_storage->setItems($itemsLow));

// wait until expired
$wait = $ttl + $capabilities->getTtlPrecision();
usleep($wait * 2000000);

$rs = $this->_storage->getItems(array_keys($items));
if (!$capabilities->getUseRequestTime()) {
$this->assertEquals(array(), $rs);
} else {
ksort($rs);
$this->assertEquals($items, $rs);
}
ksort($rs); // make comparable

$this->_options->setTtl(0);
if ($capabilities->getExpiredRead()) {
// if item expiration will be done on read there is no difference
// between the previos set items in TTL.
// -> all items will be expired
$this->assertEquals(array(), $rs);

// after disabling TTL all items will be available
$this->_options->setTtl(0);
$rs = $this->_storage->getItems(array_keys($items));
ksort($rs);
ksort($rs); // make comparable
$this->assertEquals($items, $rs);

} elseif ($capabilities->getUseRequestTime()) {
// if the request time will be used as current time all items will
// be available as expiration doesn't work within the same process
$this->assertEquals($items, $rs);

} else {
$this->assertEquals($itemsHigh, $rs);
}
}

Expand Down

0 comments on commit e59ada6

Please sign in to comment.