-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deadlock in ForkJoinPoolHierarchicalTestExecutorService
The service now checks if the `ExclusiveTask` that should run is executed on a thread that is already executing another task. If this is scenario is detected, it checks if the lock is compatible to the enclosing locks. 1. If compatible, it is executed and marked done 2. If incompatible, it is added to a list of deferred tasks and left unfinished. The deferred tasks will be re-forked afterward. fixes #3945 Co-authored-by: Marc Philipp <[email protected]>
- Loading branch information
1 parent
e951f59
commit 6da042f
Showing
7 changed files
with
178 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...tests/src/test/java/org/junit/platform/engine/support/hierarchical/ResourceLockTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.engine.support.hierarchical; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ResourceLockTests { | ||
|
||
private final ReentrantLock reentrantLock = new ReentrantLock(); | ||
|
||
@Test | ||
void singleResourceLocksThatBothHaveTheGlobalReadLockFlagAreCompatible() { | ||
SingleLock lock1 = new SingleLock(reentrantLock, true); | ||
SingleLock lock2 = new SingleLock(reentrantLock, true); | ||
assertSymmetry(lock1, lock2); | ||
} | ||
|
||
@Test | ||
void singleResourceLocksThatNotBothHaveTheGlobalReadLockFlagAreIncompatible() { | ||
SingleLock lock1 = new SingleLock(reentrantLock, true); | ||
SingleLock lock2 = new SingleLock(reentrantLock, false); | ||
SingleLock lock3 = new SingleLock(reentrantLock, false); | ||
assertSymmetryNotCompatible(lock1, lock2); | ||
assertSymmetryNotCompatible(lock1, lock3); | ||
assertSymmetryNotCompatible(lock2, lock3); | ||
} | ||
|
||
@Test | ||
void nopLocksAreCompatibleWithEverything() { | ||
ResourceLock nop = NopLock.INSTANCE; | ||
SingleLock singleLockGR = new SingleLock(reentrantLock, true); | ||
SingleLock singleLock = new SingleLock(reentrantLock, false); | ||
CompositeLock compositeLock = new CompositeLock(List.of(reentrantLock)); | ||
assertSymmetry(nop, singleLockGR); | ||
assertSymmetry(nop, singleLock); | ||
assertSymmetry(nop, compositeLock); | ||
} | ||
|
||
@Test | ||
void compositeLocksAreIncompatibleWithNonNopLocks() { | ||
CompositeLock compositeLock = new CompositeLock(List.of(reentrantLock)); | ||
SingleLock singleLockGR = new SingleLock(reentrantLock, true); | ||
SingleLock singleLock = new SingleLock(reentrantLock, false); | ||
assertSymmetryNotCompatible(compositeLock, singleLockGR); | ||
assertSymmetryNotCompatible(compositeLock, singleLock); | ||
assertSymmetryNotCompatible(compositeLock, compositeLock); | ||
} | ||
|
||
void assertSymmetry(ResourceLock a, ResourceLock b) { | ||
assertTrue(a.isCompatible(b)); | ||
assertTrue(b.isCompatible(a)); | ||
} | ||
|
||
void assertSymmetryNotCompatible(ResourceLock a, ResourceLock b) { | ||
assertFalse(a.isCompatible(b)); | ||
assertFalse(b.isCompatible(a)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters