api/symfony/Component/Semaphore/Tests/SemaphoreTest.yaml

109 lines
7.6 KiB
YAML
Raw Normal View History

2024-09-26 09:03:21 +00:00
name: SemaphoreTest
class_comment: "# * @author J\xE9r\xE9my Deruss\xE9 <jeremy@derusse.com>\n# * @author\
\ Gr\xE9goire Pineau <lyrixx@lyrixx.info>"
dependencies:
- name: TestCase
type: class
source: PHPUnit\Framework\TestCase
- name: SemaphoreAcquiringException
type: class
source: Symfony\Component\Semaphore\Exception\SemaphoreAcquiringException
- name: SemaphoreExpiredException
type: class
source: Symfony\Component\Semaphore\Exception\SemaphoreExpiredException
- name: SemaphoreReleasingException
type: class
source: Symfony\Component\Semaphore\Exception\SemaphoreReleasingException
- name: Key
type: class
source: Symfony\Component\Semaphore\Key
- name: PersistingStoreInterface
type: class
source: Symfony\Component\Semaphore\PersistingStoreInterface
- name: Semaphore
type: class
source: Symfony\Component\Semaphore\Semaphore
properties: []
methods:
- name: testExpirationResetAfter
visibility: public
parameters: []
comment: "# * @author J\xE9r\xE9my Deruss\xE9 <jeremy@derusse.com>\n# * @author\
\ Gr\xE9goire Pineau <lyrixx@lyrixx.info>\n# */\n# class SemaphoreTest extends\
\ TestCase\n# {\n# public function testAcquireReturnsTrue()\n# {\n# $key = new\
\ Key('key', 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n\
# $semaphore = new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n\
# ->method('save')\n# ->with($key, 300.0)\n# ;\n# \n# $this->assertTrue($semaphore->acquire());\n\
# $this->assertGreaterThanOrEqual(299.0, $key->getRemainingLifetime());\n# }\n\
# \n# public function testAcquireReturnsFalse()\n# {\n# $key = new Key('key',\
\ 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n# $semaphore\
\ = new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n#\
\ ->method('save')\n# ->with($key, 300.0)\n# ->willThrowException(new SemaphoreAcquiringException($key,\
\ 'message'))\n# ;\n# \n# $this->assertFalse($semaphore->acquire());\n# $this->assertNull($key->getRemainingLifetime());\n\
# }\n# \n# public function testAcquireThrowException()\n# {\n# $key = new Key('key',\
\ 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n# $semaphore\
\ = new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n#\
\ ->method('save')\n# ->with($key, 300.0)\n# ->willThrowException(new \\RuntimeException())\n\
# ;\n# \n# $this->expectException(\\RuntimeException::class);\n# $this->expectExceptionMessage('Failed\
\ to acquire the \"key\" semaphore.');\n# \n# $semaphore->acquire();\n# }\n# \n\
# public function testRefresh()\n# {\n# $key = new Key('key', 1);\n# $store =\
\ $this->createMock(PersistingStoreInterface::class);\n# $semaphore = new Semaphore($key,\
\ $store, 10.0);\n# \n# $store\n# ->expects($this->once())\n# ->method('putOffExpiration')\n\
# ->with($key, 10.0)\n# ;\n# \n# $semaphore->refresh();\n# $this->assertGreaterThanOrEqual(9.0,\
\ $key->getRemainingLifetime());\n# }\n# \n# public function testRefreshWithCustomTtl()\n\
# {\n# $key = new Key('key', 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n\
# $semaphore = new Semaphore($key, $store, 10.0);\n# \n# $store\n# ->expects($this->once())\n\
# ->method('putOffExpiration')\n# ->with($key, 40.0)\n# ;\n# \n# $semaphore->refresh(40.0);\n\
# $this->assertGreaterThanOrEqual(39.0, $key->getRemainingLifetime());\n# }\n\
# \n# public function testRefreshWhenItFails()\n# {\n# $key = new Key('key', 1);\n\
# $store = $this->createMock(PersistingStoreInterface::class);\n# $semaphore =\
\ new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n# ->method('putOffExpiration')\n\
# ->with($key, 300.0)\n# ->willThrowException(new SemaphoreExpiredException($key,\
\ 'message'))\n# ;\n# \n# $this->expectException(SemaphoreExpiredException::class);\n\
# $this->expectExceptionMessage('The semaphore \"key\" has expired: message.');\n\
# \n# $semaphore->refresh();\n# }\n# \n# public function testRefreshWhenItFailsHard()\n\
# {\n# $key = new Key('key', 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n\
# $semaphore = new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n\
# ->method('putOffExpiration')\n# ->with($key, 300.0)\n# ->willThrowException(new\
\ \\RuntimeException())\n# ;\n# \n# $this->expectException(\\RuntimeException::class);\n\
# $this->expectExceptionMessage('Failed to define an expiration for the \"key\"\
\ semaphore.');\n# \n# $semaphore->refresh();\n# }\n# \n# public function testRelease()\n\
# {\n# $key = new Key('key', 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n\
# $semaphore = new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n\
# ->method('delete')\n# ->with($key)\n# ;\n# \n# $semaphore->release();\n# }\n\
# \n# public function testReleaseWhenItFails()\n# {\n# $key = new Key('key', 1);\n\
# $store = $this->createMock(PersistingStoreInterface::class);\n# $semaphore =\
\ new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n# ->method('delete')\n\
# ->with($key)\n# ->willThrowException(new SemaphoreReleasingException($key, 'message'))\n\
# ;\n# \n# $this->expectException(SemaphoreReleasingException::class);\n# $this->expectExceptionMessage('The\
\ semaphore \"key\" could not be released: message.');\n# \n# $semaphore->release();\n\
# }\n# \n# public function testReleaseWhenItFailsHard()\n# {\n# $key = new Key('key',\
\ 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n# $semaphore\
\ = new Semaphore($key, $store);\n# \n# $store\n# ->expects($this->once())\n#\
\ ->method('delete')\n# ->with($key)\n# ->willThrowException(new \\RuntimeException())\n\
# ;\n# \n# $this->expectException(\\RuntimeException::class);\n# $this->expectExceptionMessage('Failed\
\ to release the \"key\" semaphore.');\n# \n# $semaphore->release();\n# }\n# \n\
# public function testReleaseOnDestruction()\n# {\n# $key = new Key('key', 1);\n\
# $store = $this->createMock(PersistingStoreInterface::class);\n# $semaphore =\
\ new Semaphore($key, $store);\n# \n# $store\n# ->method('exists')\n# ->willReturn(true)\n\
# ;\n# $store\n# ->expects($this->once())\n# ->method('delete')\n# ;\n# \n# $semaphore->acquire();\n\
# unset($semaphore);\n# }\n# \n# public function testNoAutoReleaseWhenNotConfigured()\n\
# {\n# $key = new Key('key', 1);\n# $store = $this->createMock(PersistingStoreInterface::class);\n\
# $semaphore = new Semaphore($key, $store, 10.0, false);\n# \n# $store\n# ->method('exists')\n\
# ->willReturn(true)\n# ;\n# $store\n# ->expects($this->never())\n# ->method('delete')\n\
# ;\n# \n# $semaphore->acquire();\n# unset($semaphore);\n# }\n# \n# public function\
\ testExpiration()\n# {\n# $store = $this->createMock(PersistingStoreInterface::class);\n\
# \n# $key = new Key('key', 1);\n# $semaphore = new Semaphore($key, $store);\n\
# $this->assertFalse($semaphore->isExpired());\n# \n# $key = new Key('key', 1);\n\
# $key->reduceLifetime(0.0);\n# $semaphore = new Semaphore($key, $store);\n# $this->assertTrue($semaphore->isExpired());\n\
# }\n# \n# /**\n# * @group time-sensitive"
traits:
- PHPUnit\Framework\TestCase
- Symfony\Component\Semaphore\Exception\SemaphoreAcquiringException
- Symfony\Component\Semaphore\Exception\SemaphoreExpiredException
- Symfony\Component\Semaphore\Exception\SemaphoreReleasingException
- Symfony\Component\Semaphore\Key
- Symfony\Component\Semaphore\PersistingStoreInterface
- Symfony\Component\Semaphore\Semaphore
interfaces: []