From fc05186286f236e776448de4618cc926cf129a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 5 Dec 2024 02:19:37 +0100 Subject: [PATCH] More lib specific lock prefix --- src/mutex/SpinlockMutex.php | 2 +- tests/mutex/MemcachedMutexTest.php | 6 +++--- tests/mutex/PredisMutexTest.php | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mutex/SpinlockMutex.php b/src/mutex/SpinlockMutex.php index 73418b8f..e177f2b9 100644 --- a/src/mutex/SpinlockMutex.php +++ b/src/mutex/SpinlockMutex.php @@ -17,7 +17,7 @@ abstract class SpinlockMutex extends LockMutex { /** The prefix for the lock key. */ - private const PREFIX = 'lock_'; + private const PREFIX = 'php-malkusch-lock:'; /** @var float The timeout in seconds a lock may live */ private $timeout; diff --git a/tests/mutex/MemcachedMutexTest.php b/tests/mutex/MemcachedMutexTest.php index 88cbf054..aed93859 100644 --- a/tests/mutex/MemcachedMutexTest.php +++ b/tests/mutex/MemcachedMutexTest.php @@ -39,7 +39,7 @@ public function testFailAcquireLock(): void $this->memcached->expects(self::atLeastOnce()) ->method('add') - ->with('lock_test', true, 2) + ->with('php-malkusch-lock:test', true, 2) ->willReturn(false); $this->mutex->synchronized(static function (): void { @@ -56,12 +56,12 @@ public function testFailReleasingLock(): void $this->memcached->expects(self::once()) ->method('add') - ->with('lock_test', true, 2) + ->with('php-malkusch-lock:test', true, 2) ->willReturn(true); $this->memcached->expects(self::once()) ->method('delete') - ->with('lock_test') + ->with('php-malkusch-lock:test') ->willReturn(false); $this->mutex->synchronized(static function (): void {}); diff --git a/tests/mutex/PredisMutexTest.php b/tests/mutex/PredisMutexTest.php index 41eff431..5cd7c3d5 100644 --- a/tests/mutex/PredisMutexTest.php +++ b/tests/mutex/PredisMutexTest.php @@ -50,7 +50,7 @@ public function testAddFailsToSetKey(): void { $this->client->expects(self::atLeastOnce()) ->method('set') - ->with('lock_test', self::isType('string'), 'PX', 3500, 'NX') + ->with('php-malkusch-lock:test', self::isType('string'), 'PX', 3500, 'NX') ->willReturn(null); $this->logger->expects(self::never()) @@ -72,7 +72,7 @@ public function testAddErrors(): void { $this->client->expects(self::atLeastOnce()) ->method('set') - ->with('lock_test', self::isType('string'), 'PX', 3500, 'NX') + ->with('php-malkusch-lock:test', self::isType('string'), 'PX', 3500, 'NX') ->willThrowException($this->createMock(PredisException::class)); $this->logger->expects(self::once()) @@ -92,12 +92,12 @@ public function testWorksNormally(): void { $this->client->expects(self::atLeastOnce()) ->method('set') - ->with('lock_test', self::isType('string'), 'PX', 3500, 'NX') + ->with('php-malkusch-lock:test', self::isType('string'), 'PX', 3500, 'NX') ->willReturnSelf(); $this->client->expects(self::once()) ->method('eval') - ->with(self::anything(), 1, 'lock_test', self::isType('string')) + ->with(self::anything(), 1, 'php-malkusch-lock:test', self::isType('string')) ->willReturn(true); $executed = false; @@ -116,12 +116,12 @@ public function testEvalScriptFails(): void { $this->client->expects(self::atLeastOnce()) ->method('set') - ->with('lock_test', self::isType('string'), 'PX', 3500, 'NX') + ->with('php-malkusch-lock:test', self::isType('string'), 'PX', 3500, 'NX') ->willReturnSelf(); $this->client->expects(self::once()) ->method('eval') - ->with(self::anything(), 1, 'lock_test', self::isType('string')) + ->with(self::anything(), 1, 'php-malkusch-lock:test', self::isType('string')) ->willThrowException($this->createMock(PredisException::class)); $this->logger->expects(self::once())