Skip to content

Commit e9195e8

Browse files
committed
Fix test: either file could obtain the lock first
1 parent 2b533db commit e9195e8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/AsyncFileTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,22 @@ public function testSimultaneousLock(): void
109109
$future1 = async(fn () => $handle1->lock(LockType::Exclusive));
110110
$future2 = async(fn () => $handle2->lock(LockType::Exclusive));
111111

112-
EventLoop::delay(0.1, fn () => $handle1->unlock());
112+
EventLoop::delay(0.1, function () use ($handle1, $handle2): void {
113+
// Either file could obtain the lock first, so check both and release the one which obtained the lock.
114+
115+
if ($handle1->getLockType()) {
116+
$handle1->unlock();
117+
}
118+
119+
if ($handle2->getLockType()) {
120+
$handle2->unlock();
121+
}
122+
});
113123

114124
$future1->await();
115125
$future2->await();
126+
127+
$handle1->close();
128+
$handle2->close();
116129
}
117130
}

0 commit comments

Comments
 (0)