Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c042bb6

Browse files
committedMay 1, 2018
Fix deadlock test on Linux to be predictable as to which threads would be chosen as the deadlock victim.
1 parent 722505f commit c042bb6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎Tests/StickyLockingTests/Locker+ExtendedLockModeTests.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ class LockerExtendedLockModeTests: XCTestCase {
601601
/// ```
602602
///
603603
func testLockConversionScenario3Example1Deadlock() {
604+
604605
let input = "database1"
605606

606607
let requester = DispatchGroup()
@@ -610,7 +611,7 @@ class LockerExtendedLockModeTests: XCTestCase {
610611
cleanup.enter()
611612
blocked.enter()
612613

613-
for _ in 0..<2 {
614+
for i in 0..<5 {
614615

615616
locked.enter()
616617
DispatchQueue.global().async(group: requester) {
@@ -620,8 +621,13 @@ class LockerExtendedLockModeTests: XCTestCase {
620621
blocked.wait()
621622

622623
/// Now upgrade the lock
623-
XCTAssertEqual(self.locker.lock(input, mode: .X, timeout: .now() + 0.2), .timeout)
624-
624+
if i <= 0 {
625+
/// the first one we send with no timeout as this will be the lock that is granted once the time out happens for the remainder of the locks.
626+
XCTAssertEqual(self.locker.lock(input, mode: .X), .granted)
627+
} else {
628+
/// These will deadlock with the first one and altimately timeout.
629+
XCTAssertEqual(self.locker.lock(input, mode: .X, timeout: .now() + 0.2), .timeout)
630+
}
625631
cleanup.wait() /// Wait to cleanup
626632

627633
XCTAssertEqual(self.locker.unlock(input), true)

0 commit comments

Comments
 (0)
Please sign in to comment.