Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(lifecycle): run start/ready hooks when FLOCI_PORT is non-default (#2439)

Anmol Mishraba97c084eb51
diff --git a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java
index f5058b6290..0a3ae41a58 100644
--- a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java
+++ b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java
@@ -49,7 +49,6 @@ import java.util.Optional;
public class EmulatorLifecycle {
private static final Logger LOG = Logger.getLogger(EmulatorLifecycle.class);
- private static final int HTTP_PORT = 4566;
private static final int TLS_HTTP_BACKEND_PORT = 4510;
@ConfigProperty(name = "quarkus.application.version", defaultValue = "")
@@ -211,7 +210,11 @@ public class EmulatorLifecycle {
}
void onHttpStart(@ObservesAsync HttpServerStart event) {
- int expectedPort = config.tls().enabled() ? TLS_HTTP_BACKEND_PORT : HTTP_PORT;
+ // Non-TLS: Quarkus listens on floci.port (quarkus.http.port: ${floci.port} in
+ // application.yml). TLS mode: TlsConfigSource pins the HTTP backend to 4510 and the
+ // public port is served by TlsProxyServer. Comparing against a hardcoded 4566 here
+ // made start/ready hooks never run when FLOCI_PORT was non-default (#2437).
+ int expectedPort = config.tls().enabled() ? TLS_HTTP_BACKEND_PORT : config.port();
if (event.options().getPort() != expectedPort) {
return;
}
diff --git a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java
index d367787767..6dd6c20da6 100644
--- a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java
+++ b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java
@@ -99,6 +99,7 @@ class EmulatorLifecycleTest {
Mockito.lenient().when(elbv2ServiceConfig.enabled()).thenReturn(false);
Mockito.lenient().when(config.tls()).thenReturn(tlsConfig);
Mockito.lenient().when(tlsConfig.enabled()).thenReturn(false);
+ Mockito.lenient().when(config.port()).thenReturn(4566);
emulatorLifecycle = new EmulatorLifecycle(
storageFactory, serviceRegistry, config,
@@ -254,6 +255,22 @@ class EmulatorLifecycleTest {
verify(initLifecycleState).markStartCompleted();
}
+ @Test
+ @DisplayName("onHttpStart on a non-default floci.port (non-TLS) triggers hook execution (#2437)")
+ void onHttpStart_nonTls_triggersHooksOnCustomPort() throws IOException, InterruptedException {
+ Mockito.lenient().when(config.port()).thenReturn(4577);
+ when(tlsConfig.enabled()).thenReturn(false);
+ when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true);
+ when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(true);
+
+ emulatorLifecycle.onHttpStart(new HttpServerStart(new HttpServerOptions().setPort(4577)));
+
+ verify(initializationHooksRunner).run(InitializationHook.START);
+ verify(initializationHooksRunner).run(InitializationHook.READY);
+ verify(initLifecycleState).markStartCompleted();
+ verify(initLifecycleState).markReadyCompleted();
+ }
+
@Test
@DisplayName("onHttpStart on wrong port (non-TLS) is ignored")
void onHttpStart_nonTls_ignoresWrongPort() throws IOException, InterruptedException {