fix(storage): flush persisted state before container teardown on shutdown (#1607)

onStop() flushed storage last, after the slow proxy/container teardown, so a graceful shutdown could be cut off by the SIGTERM grace window before buffered hybrid data was written (e.g. ECS clusters lost across a restart). Flush first; keep shutdownAll() at the end. Adds an EmulatorLifecycle ordering-guard test. Refs #1521.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-06-26 23:34:52 -05:00
1 parent 47e79b0ff5
commit 5eec726902
2 files changed
+22

No files matched your search

@@ -265,6 +265,22 @@ class EmulatorLifecycleTest {
verify(initializationHooksRunner, never()).run(InitializationHook.STOP);
}
@Test
@DisplayName("onStop flushes storage BEFORE the slow container teardown, and shuts it down last")
void shouldFlushStorageBeforeContainerTeardown() {
emulatorLifecycle.onStop(Mockito.mock(ShutdownEvent.class));
// The disk flush must run before the blocking Docker container teardown so a graceful
// shutdown can't be cut off by the SIGTERM grace window before data is persisted
// (regression guard for issue #1521). shutdownAll() still runs last to stop the flush
// schedulers and capture any shutdown-time writes.
var inOrder = Mockito.inOrder(storageFactory, rdsContainerManager, elastiCacheContainerManager);
inOrder.verify(storageFactory).flushAll();
inOrder.verify(elastiCacheContainerManager).stopAll();
inOrder.verify(rdsContainerManager).stopAll();
inOrder.verify(storageFactory).shutdownAll();
}
@Test
@DisplayName("Should still run full resource cleanup when a pre-shutdown hook fails")
void shouldRunFullCleanupAfterFailingPreShutdownHook() throws IOException, InterruptedException {