Skip to content

Commit

Permalink
Fix test: either file could obtain the lock first
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 9, 2024
1 parent 2b533db commit e9195e8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/AsyncFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,22 @@ public function testSimultaneousLock(): void
$future1 = async(fn () => $handle1->lock(LockType::Exclusive));
$future2 = async(fn () => $handle2->lock(LockType::Exclusive));

EventLoop::delay(0.1, fn () => $handle1->unlock());
EventLoop::delay(0.1, function () use ($handle1, $handle2): void {
// Either file could obtain the lock first, so check both and release the one which obtained the lock.

if ($handle1->getLockType()) {
$handle1->unlock();
}

if ($handle2->getLockType()) {
$handle2->unlock();
}
});

$future1->await();
$future2->await();

$handle1->close();
$handle2->close();
}
}

0 comments on commit e9195e8

Please sign in to comment.