2015-09-26 06:41:15 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:36:58 +02:00
|
|
|
namespace Amp\Concurrent\Test\Sync;
|
2016-08-18 18:04:48 +02:00
|
|
|
|
|
|
|
use Amp\Concurrent\Sync\Lock;
|
2016-08-19 00:36:58 +02:00
|
|
|
use Amp\Concurrent\Test\TestCase;
|
2015-09-26 06:41:15 +02:00
|
|
|
|
2016-08-19 00:36:58 +02:00
|
|
|
class LockTest extends TestCase {
|
|
|
|
public function testIsReleased() {
|
2015-09-26 06:41:15 +02:00
|
|
|
$lock = new Lock($this->createCallback(1));
|
|
|
|
$this->assertFalse($lock->isReleased());
|
|
|
|
$lock->release();
|
|
|
|
$this->assertTrue($lock->isReleased());
|
|
|
|
}
|
|
|
|
|
2016-08-19 00:36:58 +02:00
|
|
|
public function testIsReleasedOnDestruct() {
|
2015-09-26 06:41:15 +02:00
|
|
|
$lock = new Lock($this->createCallback(1));
|
|
|
|
unset($lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-19 00:36:58 +02:00
|
|
|
* @expectedException \Amp\Concurrent\LockAlreadyReleasedError
|
2015-09-26 06:41:15 +02:00
|
|
|
*/
|
2016-08-19 00:36:58 +02:00
|
|
|
public function testThrowsOnMultiRelease() {
|
2015-09-26 06:41:15 +02:00
|
|
|
$lock = new Lock($this->createCallback(1));
|
|
|
|
$lock->release();
|
|
|
|
$lock->release();
|
|
|
|
}
|
|
|
|
}
|