mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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 <AndreKurait@gmail.com> * 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 <AndreKurait@gmail.com> --------- Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
485f78656b
commit
1cafa71e3d
1 file changed
+6
-20
@@ -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<Integer> 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<Boolean> 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");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user