From 67b408aa22c31e30ca4af38cf976c4c81fc06e92 Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Mon, 2 Nov 2026 09:08:19 -0600 Subject: [PATCH] perf(elbv2): drive TCP fixture health probes explicitly (#7328) --- .../services/elbv2/ElbV2HealthChecker.java | 2 +- .../elbv2/ElbV2HealthCheckerTest.java | 38 +++++++++++++++++++ .../ElbV2TcpDataPlaneIntegrationTest.java | 23 +++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthChecker.java b/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthChecker.java index 8f72ce4589..789aed7561 100644 --- a/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthChecker.java +++ b/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthChecker.java @@ -126,7 +126,7 @@ public class ElbV2HealthChecker implements Resettable { return "healthy".equals(state) || "initial".equals(state); } - private void probeAll(String tgArn, TargetGroup tg) { + void probeAll(String tgArn, TargetGroup tg) { Map tgStates = states.get(tgArn); if (tgStates == null || !Boolean.TRUE.equals(tg.getHealthCheckEnabled())) { return; diff --git a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthCheckerTest.java b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthCheckerTest.java index c51fbd8d02..40cfb4b38a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthCheckerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2HealthCheckerTest.java @@ -19,6 +19,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -28,6 +29,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; class ElbV2HealthCheckerTest { @@ -259,6 +261,42 @@ class ElbV2HealthCheckerTest { assertNull(healthy.description()); } + @Test + @SuppressWarnings("unchecked") + void periodicProbeRetainsIntervalAndNetworkAdmissionThreshold() { + Vertx scheduled = mock(Vertx.class); + when(scheduled.executeBlocking(any(Callable.class))).thenReturn(Future.succeededFuture(200)); + AtomicReference> periodic = new AtomicReference<>(); + doAnswer(invocation -> { + Handler callback = invocation.getArgument(1); + callback.handle(1L); + return 1L; + }).when(scheduled).setTimer(anyLong(), any()); + doAnswer(invocation -> { + assertEquals(5000L, invocation.getArgument(0)); + periodic.set(invocation.getArgument(1)); + return 2L; + }).when(scheduled).setPeriodic(anyLong(), any()); + EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); + when(config.services().elbv2().mock()).thenReturn(false); + ElbV2HealthChecker checker = new ElbV2HealthChecker(scheduled, config, mock(Ec2Service.class)); + TargetGroup group = targetGroup(8080, "200", 2, 1); + group.setProtocol("TCP"); + group.setHealthCheckIntervalSeconds(5); + TargetDescription target = target("127.0.0.1", 8080); + + checker.startMonitoring(group); + checker.addTargets(group.getTargetGroupArn(), List.of(target), group); + assertEquals("initial", checker.getState(group.getTargetGroupArn(), target.getId(), target.getPort())); + assertEquals("Elb.InitialHealthChecking", + checker.getHealth(group.getTargetGroupArn(), target.getId(), target.getPort()).reason()); + periodic.get().handle(2L); + assertEquals("healthy", checker.getState(group.getTargetGroupArn(), target.getId(), target.getPort())); + checker.stopMonitoring(group.getTargetGroupArn()); + verify(scheduled).cancelTimer(2L); + assertEquals("initial", checker.getState(group.getTargetGroupArn(), target.getId(), target.getPort())); + } + private ElbV2HealthChecker healthChecker() { EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); when(config.services().elbv2().mock()).thenReturn(false); diff --git a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2TcpDataPlaneIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2TcpDataPlaneIntegrationTest.java index 649eeed8e1..9a5e3eeb74 100644 --- a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2TcpDataPlaneIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2TcpDataPlaneIntegrationTest.java @@ -37,6 +37,7 @@ import software.amazon.awssdk.services.elasticloadbalancingv2.model.LoadBalancer import software.amazon.awssdk.services.elasticloadbalancingv2.model.LoadBalancerTypeEnum; import software.amazon.awssdk.services.elasticloadbalancingv2.model.ProtocolEnum; import software.amazon.awssdk.services.elasticloadbalancingv2.model.TargetDescription; +import software.amazon.awssdk.services.elasticloadbalancingv2.model.TargetHealthDescription; import software.amazon.awssdk.services.elasticloadbalancingv2.model.TargetHealthStateEnum; import software.amazon.awssdk.services.elasticloadbalancingv2.model.TargetTypeEnum; @@ -76,6 +77,12 @@ class ElbV2TcpDataPlaneIntegrationTest { @Inject ElbV2DataPlane dataPlane; + @Inject + ElbV2HealthChecker healthChecker; + + @Inject + ElbV2Service service; + @TestHTTPResource URI endpoint; @@ -123,6 +130,8 @@ class ElbV2TcpDataPlaneIntegrationTest { client.registerTargets(request -> request.targetGroupArn(targetGroupArn) .targets(TargetDescription.builder().id("127.0.0.1").port(backend.actualPort()).build())); + completeInitialHealthChecks(1); + await().atMost(Duration.ofSeconds(15)).untilAsserted(() -> assertEquals( TargetHealthStateEnum.HEALTHY, client.describeTargetHealth(request -> request.targetGroupArn(targetGroupArn)) @@ -145,6 +154,19 @@ class ElbV2TcpDataPlaneIntegrationTest { }); } + private void completeInitialHealthChecks(int expectedTargets) { + await().atMost(Duration.ofSeconds(5)).untilAsserted(() -> { + List descriptions = client.describeTargetHealth( + request -> request.targetGroupArn(targetGroupArn)).targetHealthDescriptions(); + assertEquals(expectedTargets, descriptions.size()); + assertTrue(descriptions.stream().allMatch(description -> + description.targetHealth().state() == TargetHealthStateEnum.HEALTHY + || "Elb.InitialHealthChecking".equals(description.targetHealth().reasonAsString()))); + }); + // Keep the real network probes and threshold, without waiting for the periodic timer. + healthChecker.probeAll(targetGroupArn, service.getTargetGroup("us-east-1", targetGroupArn)); + } + @AfterEach void cleanup() { assertAll("Clean up every TCP fixture resource even if another cleanup fails", @@ -352,6 +374,7 @@ class ElbV2TcpDataPlaneIntegrationTest { try { client.registerTargets(request -> request.targetGroupArn(targetGroupArn).targets(TargetDescription.builder() .id("127.0.0.1").port(second.actualPort()).build())); + completeInitialHealthChecks(2); await().atMost(Duration.ofSeconds(15)).untilAsserted(() -> { List states = client.describeTargetHealth(request -> request .targetGroupArn(targetGroupArn)).targetHealthDescriptions().stream()