mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): warn before runtime api port exhaustion (#3496)
This commit is contained in:
1 parent
eb622254bc
commit
bea8f85f62
2 files changed
+76
-10
No files matched your search
@@ -2,14 +2,18 @@ package io.github.hectorvent.floci.core.common.port;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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 static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PortAllocatorTest {
|
||||
|
||||
@@ -51,13 +55,6 @@ class PortAllocatorTest {
|
||||
assertThrows(IllegalStateException.class, allocator::allocate);
|
||||
}
|
||||
|
||||
/**
|
||||
* When the pool runs dry the exception is often the only artefact an operator ever sees —
|
||||
* it reaches them second-hand as a CloudFormation rollback, with floci's own logs the only
|
||||
* place the cause survives (issue #2206). "No free ports in range 9200-9299" does not say
|
||||
* which pool ran dry or how to widen it, leaving the reader to find PortAllocator in the
|
||||
* source to discover the knob exists. The message must carry its own diagnosis.
|
||||
*/
|
||||
@Test
|
||||
void exhaustionMessageNamesThePoolAndTheWideningProperty() {
|
||||
PortAllocator allocator = new PortAllocator(9200, 9200);
|
||||
@@ -74,6 +71,37 @@ class PortAllocatorTest {
|
||||
"message must still report the exhausted range; got: " + message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void warnsOnceWhenPoolCrossesNinetyPercent() {
|
||||
List<String> warnings = new ArrayList<>();
|
||||
PortAllocator allocator = new PortAllocator(9200, 9209, warnings::add);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
allocator.allocate();
|
||||
}
|
||||
|
||||
assertEquals(1, warnings.size());
|
||||
assertTrue(warnings.getFirst().contains("90% allocated"));
|
||||
assertTrue(warnings.getFirst().contains("9/10 ports"));
|
||||
assertTrue(warnings.getFirst().contains("runtime-api-max-port"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void warningRearmsAfterPressureDropsBelowThreshold() {
|
||||
List<String> warnings = new ArrayList<>();
|
||||
PortAllocator allocator = new PortAllocator(9200, 9209, warnings::add);
|
||||
List<Integer> ports = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ports.add(allocator.allocate());
|
||||
}
|
||||
allocator.release(ports.getLast());
|
||||
ports.removeLast();
|
||||
ports.add(allocator.allocate());
|
||||
|
||||
assertEquals(2, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void releasedPortBecomesAvailableAgain() {
|
||||
PortAllocator allocator = new PortAllocator(9200, 9201);
|
||||
|
||||
Reference in new issue
Block a user