1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-11 16:49:51 +01:00
parallel/test/Sync/FileMutexTest.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2016-08-22 06:40:48 +02:00
<?php declare(strict_types = 1);
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\FileMutex;
2016-08-19 00:36:58 +02:00
use Amp\Concurrent\Test\TestCase;
class FileMutexTest extends TestCase {
public function testAcquire() {
\Amp\execute(function () {
2016-08-23 01:25:19 +02:00
$mutex = new FileMutex;
2016-08-19 00:36:58 +02:00
$lock = yield $mutex->acquire();
$lock->release();
$this->assertTrue($lock->isReleased());
2016-08-19 00:36:58 +02:00
});
}
2016-08-19 00:36:58 +02:00
public function testAcquireMultiple() {
$this->assertRunTimeGreaterThan(function () {
2016-08-19 00:36:58 +02:00
\Amp\execute(function () {
2016-08-23 01:25:19 +02:00
$mutex = new FileMutex;
2016-08-19 00:36:58 +02:00
$lock1 = yield $mutex->acquire();
\Amp\delay(500, function () use ($lock1) {
$lock1->release();
});
2016-08-19 00:36:58 +02:00
$lock2 = yield $mutex->acquire();
\Amp\delay(500, function () use ($lock2) {
$lock2->release();
});
2016-08-19 00:36:58 +02:00
$lock3 = yield $mutex->acquire();
\Amp\delay(500, function () use ($lock3) {
$lock3->release();
});
});
}, 1.5);
}
}