Skip to content

Commit 14d5f9a

Browse files
committed
Polishing
1 parent fdb5fac commit 14d5f9a

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ConcurrentHierarchicalTestExecutorService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ private record Entry(TestTask task, CompletableFuture<@Nullable Void> future, in
574574
implements Comparable<Entry> {
575575

576576
static Entry create(TestTask task) {
577-
int level = task.getTestDescriptor().getUniqueId().getSegments().size();
578-
return new Entry(task, new CompletableFuture<>(), level, 0);
577+
return createWithIndex(task, 0);
579578
}
580579

581580
static Entry createWithIndex(TestTask task, int index) {

platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ConcurrentHierarchicalTestExecutorServiceTests.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import static java.util.concurrent.Future.State.SUCCESS;
1515
import static java.util.function.Predicate.isEqual;
1616
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.junit.jupiter.api.Assertions.assertAll;
1817
import static org.junit.jupiter.api.Assertions.fail;
1918
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;
2019
import static org.junit.platform.commons.util.ExceptionUtils.throwAsUncheckedException;
@@ -374,20 +373,17 @@ public void release() {
374373
.containsOnly(child2.executionThread);
375374
}
376375

377-
@Test
376+
@RepeatedTest(value = 100, failureThreshold = 1)
378377
void executesChildrenInOrder() throws Exception {
379378
service = new ConcurrentHierarchicalTestExecutorService(configuration(1, 1));
380379

381-
Executable behavior = () -> {
382-
383-
};
384-
var leaf1a = new TestTaskStub(ExecutionMode.CONCURRENT, behavior) //
380+
var leaf1a = new TestTaskStub(ExecutionMode.CONCURRENT) //
385381
.withName("leaf1a").withLevel(2);
386-
var leaf1b = new TestTaskStub(ExecutionMode.CONCURRENT, behavior) //
382+
var leaf1b = new TestTaskStub(ExecutionMode.CONCURRENT) //
387383
.withName("leaf1b").withLevel(2);
388-
var leaf1c = new TestTaskStub(ExecutionMode.CONCURRENT, behavior) //
384+
var leaf1c = new TestTaskStub(ExecutionMode.CONCURRENT) //
389385
.withName("leaf1c").withLevel(2);
390-
var leaf1d = new TestTaskStub(ExecutionMode.CONCURRENT, behavior) //
386+
var leaf1d = new TestTaskStub(ExecutionMode.CONCURRENT) //
391387
.withName("leaf1d").withLevel(2);
392388

393389
var root = new TestTaskStub(ExecutionMode.SAME_THREAD,
@@ -399,12 +395,12 @@ void executesChildrenInOrder() throws Exception {
399395
assertThat(List.of(root, leaf1a, leaf1b, leaf1c, leaf1d)) //
400396
.allSatisfy(TestTaskStub::assertExecutedSuccessfully);
401397

402-
assertAll(() -> assertThat(leaf1a.startTime).isBeforeOrEqualTo(leaf1b.startTime),
403-
() -> assertThat(leaf1b.startTime).isBeforeOrEqualTo(leaf1c.startTime),
404-
() -> assertThat(leaf1c.startTime).isBeforeOrEqualTo(leaf1d.startTime));
398+
assertThat(Stream.of(leaf1a, leaf1b, leaf1c, leaf1d)) //
399+
.extracting(TestTaskStub::startTime) //
400+
.isSorted();
405401
}
406402

407-
@Test
403+
@RepeatedTest(value = 100, failureThreshold = 1)
408404
void workIsStolenInReverseOrder() throws Exception {
409405
service = new ConcurrentHierarchicalTestExecutorService(configuration(2, 2));
410406

@@ -440,16 +436,19 @@ void workIsStolenInReverseOrder() throws Exception {
440436
// If the last node was stolen.
441437
assertThat(leaf1a.executionThread).isNotEqualTo(leaf2c.executionThread);
442438
// Then it must follow that the last half of the nodes were stolen
443-
assertThat(Stream.of(leaf1a, leaf1b, leaf1c, leaf2a, leaf2b, leaf2c)).extracting(
444-
TestTaskStub::executionThread).containsExactly( //
445-
leaf1a.executionThread, leaf1a.executionThread, leaf1a.executionThread, //
446-
leaf2c.executionThread, leaf2c.executionThread, leaf2c.executionThread //
447-
);
448-
assertAll( //
449-
() -> assertThat(leaf1a.startTime).isBeforeOrEqualTo(leaf1b.startTime),
450-
() -> assertThat(leaf1b.startTime).isBeforeOrEqualTo(leaf1c.startTime),
451-
() -> assertThat(leaf2a.startTime).isAfterOrEqualTo(leaf2b.startTime),
452-
() -> assertThat(leaf2b.startTime).isAfterOrEqualTo(leaf2c.startTime));
439+
assertThat(Stream.of(leaf1a, leaf1b, leaf1c)) //
440+
.extracting(TestTaskStub::executionThread) //
441+
.containsOnly(leaf1a.executionThread);
442+
assertThat(Stream.of(leaf2a, leaf2b, leaf2c)) //
443+
.extracting(TestTaskStub::executionThread) //
444+
.containsOnly(leaf2c.executionThread);
445+
446+
assertThat(Stream.of(leaf1a, leaf1b, leaf1c)) //
447+
.extracting(TestTaskStub::startTime) //
448+
.isSorted();
449+
assertThat(Stream.of(leaf2c, leaf2b, leaf2a)) //
450+
.extracting(TestTaskStub::startTime) //
451+
.isSorted();
453452
}
454453

455454
private static ExclusiveResource exclusiveResource(LockMode lockMode) {
@@ -567,6 +566,11 @@ Thread executionThread() {
567566
return executionThread;
568567
}
569568

569+
@Nullable
570+
Instant startTime() {
571+
return startTime;
572+
}
573+
570574
@Override
571575
public String toString() {
572576
return "%s @ %s".formatted(new ToStringBuilder(this).append("name", name), Integer.toHexString(hashCode()));

0 commit comments

Comments
 (0)