From 1cafa71e3d0ecc24f3ef5cf4c316d6499150d102 Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Fri, 30 Oct 2026 09:34:33 -0500 Subject: [PATCH] test(port): reuse shared start gate for Runtime API allocations (#7009) * test(port): bound concurrent allocation fixture failures Propagate worker failures, synchronize allocation admission under one monotonic deadline, and retain cleanup failures without hiding the primary cause. Preserve all existing allocator scenarios and the 50-worker uniqueness check. Signed-off-by: Andre Kurait * test(port): reuse shared start gate for allocation workers Use the existing StartGate helper to release allocation tasks together, collect worker errors and bound executor shutdown. Remove the duplicate runner and its eight helper-only tests, preserving all eight allocator scenarios. Signed-off-by: Andre Kurait --------- Signed-off-by: Andre Kurait --- .../core/common/port/PortAllocatorTest.java | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/test/java/io/github/hectorvent/floci/core/common/port/PortAllocatorTest.java b/src/test/java/io/github/hectorvent/floci/core/common/port/PortAllocatorTest.java index 37d0a46049..15c2e63aa9 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/port/PortAllocatorTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/port/PortAllocatorTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.core.common.port; +import io.github.hectorvent.floci.testing.StartGate; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -9,15 +10,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.function.IntPredicate; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assumptions.assumeTrue; class PortAllocatorTest { @@ -35,22 +30,13 @@ class PortAllocatorTest { } @Test - void concurrentAllocationsAreUnique() throws InterruptedException { + void concurrentAllocationsAreUnique() throws Exception { PortAllocator allocator = new PortAllocator(9200, 9299, w -> { }, ALWAYS_BINDABLE); int threads = 50; Set ports = ConcurrentHashMap.newKeySet(); - CountDownLatch latch = new CountDownLatch(threads); - ExecutorService executor = Executors.newFixedThreadPool(threads); - - for (int i = 0; i < threads; i++) { - executor.submit(() -> { - ports.add(allocator.allocate()); - latch.countDown(); - }); - } - - latch.await(); - executor.shutdown(); + StartGate.Results results = StartGate.runConcurrently(threads, + index -> ports.add(allocator.allocate())); + assertTrue(results.errors().isEmpty(), () -> "Allocation workers failed: " + results.errors()); assertEquals(threads, ports.size(), "All allocated ports must be unique"); }