Skip to content

Commit

Permalink
Added assert to verify no lock data is stored in the APCu storage whe…
Browse files Browse the repository at this point in the history
…n all the locks are available
  • Loading branch information
avpaderno committed Feb 17, 2025
1 parent 44332e7 commit c34044d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions includes/apc_storage_lock.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion modules/apc_storage_admin/apc_storage_admin.module
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
)
Expand Down
18 changes: 16 additions & 2 deletions tests/apc_storage_lock.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
}
}
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/apc_storage_queue.test
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);

Expand Down

0 comments on commit c34044d

Please sign in to comment.