From c34044dcf8cc32bc2a754d014ceaf31789a60023 Mon Sep 17 00:00:00 2001 From: Alberto Paderno Date: Mon, 17 Feb 2025 20:50:00 +0100 Subject: [PATCH] Added assert to verify no lock data is stored in the APCu storage when all the locks are available --- includes/apc_storage_lock.class.inc | 6 +++--- .../apc_storage_admin/apc_storage_admin.module | 2 +- tests/apc_storage_lock.test | 18 ++++++++++++++++-- tests/apc_storage_queue.test | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/includes/apc_storage_lock.class.inc b/includes/apc_storage_lock.class.inc index d504274..5d7020f 100644 --- a/includes/apc_storage_lock.class.inc +++ b/includes/apc_storage_lock.class.inc @@ -100,7 +100,7 @@ class ApcStorageLock { if (apcu_exists($this->key)) { // Try to extend the expiration of an already acquired lock. - if (!apcu_store($this->key, array('expire' => $expire), 0)) { + if (!apcu_store($this->key, array('expire' => $expire))) { // The lock was broken. apcu_delete($this->key); @@ -118,12 +118,12 @@ class ApcStorageLock { // We always want to do this code at least once. do { - $success = apcu_store($this->key, array('expire' => $expire), 0); + $success = apcu_store($this->key, array('expire' => $expire)); if (!$success) { // If this is our first pass through the loop, then $retry is FALSE. // In this case, the insert must have failed meaning some other - // request acquired the lock but did not release it. + // request acquired the lock but did not release it. // We decide whether to retry by checking // ApcStorageLock::maybeAvailable(), since this will break the lock in // case it is expired. diff --git a/modules/apc_storage_admin/apc_storage_admin.module b/modules/apc_storage_admin/apc_storage_admin.module index 7ec8f2d..e72dff0 100644 --- a/modules/apc_storage_admin/apc_storage_admin.module +++ b/modules/apc_storage_admin/apc_storage_admin.module @@ -111,7 +111,7 @@ function apc_storage_admin_settings($form, &$form_state): array { $form['#config'] = 'apc_storage.admin'; - $description = t('User accounts with the !permission permission will be see which data is stored in the APCu storage.', + $description = t('User accounts with the !permission permission will see which data is stored in the APCu storage.', array( '!permission' => l(t('Access APC Storage reports'), 'admin/config/people/permissions', array('fragment' => 'module-apc-storage-admin')), ) diff --git a/tests/apc_storage_lock.test b/tests/apc_storage_lock.test index 302f8d6..9712f95 100644 --- a/tests/apc_storage_lock.test +++ b/tests/apc_storage_lock.test @@ -159,13 +159,27 @@ class ApcStorageLockTestCase extends ApcStorageBaseTestCase { $this->pass(format_string('Tests will be halted for @delay seconds.', array('@delay' => $delay))); sleep($delay); + $count = 0; + foreach ($locks as $name => $lock) { $message = format_string( 'The @name lock is available after further @delay seconds.', array('@name' => $name, '@delay' => $delay) ); - $this->assertTrue($lock->maybeAvailable(), $message); + if ($this->assertTrue($lock->maybeAvailable(), $message)) { + $count++; + } + } + + if ($count == count($this->lockNames)) { + $this->assertNoApcuKeysByPrefix( + 'apc_storage_lock::[a-zA-Z0-9-_]+::', + array( + 'message' => 'All locks are available and no lock data is stored in the APCu storage.', + 'regexp' => TRUE + ) + ); } } } @@ -183,7 +197,7 @@ class ApcStorageLockTestCase extends ApcStorageBaseTestCase { } if ($this->assertTrue($this->initLocks(), 'All the locks have been created.')) { - $max_timeout = $this->acquireLocks(2.0, 4.0); + $max_timeout = $this->acquireLocks(2.0, 4.0) + 1.0; $lock = ApcStorageLock::get($this->lockNames[0]); $message = format_string( diff --git a/tests/apc_storage_queue.test b/tests/apc_storage_queue.test index e5e5282..fdbefbe 100644 --- a/tests/apc_storage_queue.test +++ b/tests/apc_storage_queue.test @@ -114,7 +114,7 @@ class ApcStorageQueueTestCase extends ApcStorageBaseTestCase { if ($this->initQueues()) { foreach ($this->queues as $name => $data) { $message = format_string( - 'Data for the @queue queue has been stored on the APCu storage.', + 'Data for the @queue queue has been stored in the APCu storage.', array('@queue' => $name), );