Skip to content
Snippets Groups Projects
Verified Commit 47fb1408 authored by Alberto Paderno's avatar Alberto Paderno
Browse files

Issue #3470139: Update the cache tests to verify there are no conflicts with the lock keys

parent e4f80c43
No related branches found
No related tags found
1 merge request!75Issue #3470139: Update the cache tests to verify there are no conflicts with the lock keys
Pipeline #267476 passed
......@@ -977,6 +977,26 @@ class ApcCacheConflictingKeysTestCase extends ApcCacheBaseTestCase {
*/
class ApcCachePreserveExistingApcuKeysTestCase extends ApcCacheBaseTestCase {
/**
* Returns the key name used for locks.
*
* This method uses code similar to the code in
* ApcCacheTestTrait::getLockKey(). It is duplicated here because including
* the drupal_apc_lock.inc file would cause an error about functions already
* defined.
*/
protected function getLockKey($name) {
static $unique_id;
if (empty($unique_id)) {
$unique_id = drupal_random_bytes(32);
}
$hash = hash('sha256', $unique_id . $name, TRUE);
return 'apc_lock::' . drupal_base64_encode($hash);
}
/**
* {@inheritdoc}
*/
......@@ -992,12 +1012,14 @@ class ApcCachePreserveExistingApcuKeysTestCase extends ApcCacheBaseTestCase {
* {@inheritdoc}
*/
protected function setUp() {
$this->setCacheBins('apc_cache::', 'apc_cache::default_prefix::');
$this->setCacheBins('apc_cache', 'apc_cache::', 'apc_cache::default_prefix::', 'apc_lock', 'apc_lock::');
parent::setUp();
}
/**
* Tests that writing cache items does not change other APCu values.
*
* This test also verifies that locks stored in APCu are preserved.
*/
public function testWriteFirstApcuValues() {
$stored = array();
......@@ -1007,9 +1029,9 @@ class ApcCachePreserveExistingApcuKeysTestCase extends ApcCacheBaseTestCase {
}
if ($this->assertApcuEmpty() && $this->assertCacheBinsOnApcu()) {
foreach ($this->getCacheBins(TRUE) as $bin) {
foreach ($this->getCacheBins() as $bin) {
foreach ($this->storageData() as $id => $data) {
$key = "$bin$id";
$key = $this->getLockKey("$bin$id");
if ($this->assertApcuKeySaved($key, $data['value'])) {
$stored[$key] = $data;
......@@ -1042,6 +1064,8 @@ class ApcCachePreserveExistingApcuKeysTestCase extends ApcCacheBaseTestCase {
/**
* Tests that writing APCu values does not change cache items.
*
* This test also verifies that locks stored in APCu are preserved.
*/
public function testWriteFirstCacheItems() {
$stored = array();
......@@ -1051,7 +1075,7 @@ class ApcCachePreserveExistingApcuKeysTestCase extends ApcCacheBaseTestCase {
}
if ($this->assertApcuEmpty() && $this->assertCacheBinsOnApcu()) {
foreach ($this->getCacheBins(TRUE) as $bin) {
foreach ($this->getCacheBins() as $bin) {
foreach ($this->storageData() as $id => $data) {
if ($this->assertCacheItemSaved($bin, $id, $data['value'])) {
$data['bin'] = $bin;
......@@ -1064,9 +1088,9 @@ class ApcCachePreserveExistingApcuKeysTestCase extends ApcCacheBaseTestCase {
$message = 'New items were stored in the cache.';
if ($this->assertTrue(!empty($stored), $message)) {
foreach ($this->getCacheBins(TRUE) as $bin) {
foreach ($this->getCacheBins() as $bin) {
foreach ($this->storageData() as $id => $data) {
$key = "$bin$id";
$key = $this->getLockKey("$bin$id");
if ($this->assertApcuKeySaved($key, $data['value'])) {
$count++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment