1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-04 10:38:30 +01:00
parallel/tests/Sync/FileMutexTest.php

51 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Icicle\Tests\Concurrent\Sync;
use Icicle\Concurrent\Sync\FileMutex;
use Icicle\Coroutine;
use Icicle\Loop;
use Icicle\Tests\Concurrent\TestCase;
class FileMutexTest extends TestCase
{
public function testAcquire()
{
Coroutine\create(function () {
$mutex = new FileMutex();
2016-01-23 07:00:56 +01:00
$lock = yield from $mutex->acquire();
$lock->release();
$this->assertTrue($lock->isReleased());
})->done();
Loop\run();
}
public function testAcquireMultiple()
{
Loop\loop();
$this->assertRunTimeGreaterThan(function () {
Coroutine\create(function () {
$mutex = new FileMutex();
2016-01-23 07:00:56 +01:00
$lock1 = yield from $mutex->acquire();
Loop\timer(0.5, function () use ($lock1) {
$lock1->release();
});
2016-01-23 07:00:56 +01:00
$lock2 = yield from $mutex->acquire();
Loop\timer(0.5, function () use ($lock2) {
$lock2->release();
});
2016-01-23 07:00:56 +01:00
$lock3 = yield from $mutex->acquire();
Loop\timer(0.5, function () use ($lock3) {
$lock3->release();
});
});
Loop\run();
}, 1.5);
}
}