php-ipc/tests/Sem/SemaphoreTest.php

27 lines
631 B
PHP

<?php
namespace NoccyLabs\Ipc\Sem;
use NoccyLabs\Ipc\Key\FileKey;
class SemaphoreTest extends \PhpUnit\Framework\TestCase
{
public function testCreatingAndAquiringSemaphore()
{
$key = new FileKey(__FILE__);
$sem = new Semaphore($key, 2);
$this->assertTrue($sem->acquire());
$this->assertTrue($sem->acquire());
$this->assertFalse($sem->acquire());
$this->assertTrue($sem->release());
$this->assertTrue($sem->acquire());
$this->assertFalse($sem->acquire());
$this->assertTrue($sem->release());
$this->assertTrue($sem->release());
}
}