mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
perf(lambda): avoid code-copy helper shutdown delay (#5646)
* perf(lambda): avoid code-copy helper shutdown delay * test(lambda): scope the code-copy fixture threshold Signed-off-by: Andre Kurait <akurait@amazon.com> * chore(ci): retry the EKS registry fixture check Signed-off-by: Andre Kurait <akurait@amazon.com> --------- Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
5a72b4f561
commit
f08a443ec9
3 files changed
+54
-2
No files matched your search
+48
-1
@@ -1017,6 +1017,7 @@ class ContainerLauncherTest {
|
||||
fn.setHandler("index.handler");
|
||||
fn.setCodeLocalPath(codePath.toString());
|
||||
fn.setCodeSha256("large-fn-sha-v1");
|
||||
when(lifecycleManager.create(any())).thenReturn("helper-123", "container-123");
|
||||
|
||||
long original = ContainerLauncher.CODE_VOLUME_MIN_BYTES;
|
||||
try {
|
||||
@@ -1042,13 +1043,49 @@ class ContainerLauncherTest {
|
||||
// Two creates: the helper + the real container. The helper is discarded.
|
||||
verify(lifecycleManager, times(2)).create(any());
|
||||
verify(lifecycleManager, atLeastOnce()).ensureVolume(any());
|
||||
verify(lifecycleManager, times(1)).stopAndRemove(any(), any()); // the helper only
|
||||
verify(lifecycleManager).stopAndRemove("helper-123", null, 0);
|
||||
verify(lifecycleManager, never()).stopAndRemove(any(), any());
|
||||
InOrder order = inOrder(lifecycleManager);
|
||||
order.verify(lifecycleManager).stopAndRemove("helper-123", null, 0);
|
||||
order.verify(lifecycleManager).create(any());
|
||||
order.verify(lifecycleManager).startCreated(eq("container-123"), any());
|
||||
// A superseded code-version volume is never deleted synchronously within a single launch
|
||||
// (see the cleanupSupersededVolumes tests below for the deferred sweep; this fn has no
|
||||
// prior volume to supersede, since it's the fn's first deploy here).
|
||||
verify(lifecycleManager, never()).removeVolume(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void launchFunction_failedCodeCopyImmediatelyRemovesOnlyItsHelper() throws Exception {
|
||||
Path codePath = Files.createDirectory(tempDir.resolve("failed-code-copy"));
|
||||
Files.write(codePath.resolve("bundle.bin"), new byte[8 * 1024]);
|
||||
LambdaFunction fn = new LambdaFunction();
|
||||
fn.setFunctionName("copy-failure");
|
||||
fn.setRuntime("nodejs20.x");
|
||||
fn.setHandler("index.handler");
|
||||
fn.setCodeLocalPath(codePath.toString());
|
||||
fn.setCodeSha256("copy-failure-sha");
|
||||
when(lifecycleManager.create(any())).thenReturn("helper-123");
|
||||
doThrow(new IllegalStateException("fixture copy failed"))
|
||||
.when(dockerClient).copyArchiveToContainerCmd("helper-123");
|
||||
|
||||
withLoweredCodeVolumeThreshold(() -> {
|
||||
RuntimeException failure = assertThrows(RuntimeException.class, () -> launcher.launch(fn));
|
||||
assertTrue(failure.getMessage().contains("fixture copy failed"));
|
||||
});
|
||||
|
||||
InOrder order = inOrder(lifecycleManager, dockerClient);
|
||||
order.verify(lifecycleManager).startCreated(eq("helper-123"), any());
|
||||
order.verify(dockerClient).copyArchiveToContainerCmd("helper-123");
|
||||
order.verify(lifecycleManager).stopAndRemove("helper-123", null, 0);
|
||||
verify(lifecycleManager, times(1)).create(any());
|
||||
verify(lifecycleManager, never()).stopAndRemove(any(), any());
|
||||
verify(lifecycleManager, never()).removeVolume(any());
|
||||
verify(runtimeApiServerFactory).release(runtimeApiServer);
|
||||
assertFalse(Files.exists(tempDir.resolve("lambda-codevol-markers")
|
||||
.resolve(ContainerLauncher.codeVolumeName(fn))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void launchFunction_releasesRuntimeApiServer_whenCodeVolumePopulateFails() throws Exception {
|
||||
// Regression for the runtime-api port leak: the volume path allocates a runtime-api server
|
||||
@@ -1915,4 +1952,14 @@ class ContainerLauncherTest {
|
||||
assertEquals(List.of("/opt/extensions/lambda-adapter", "/opt/extensions/otel-collector"),
|
||||
capturedLaunchPaths(launchCmds));
|
||||
}
|
||||
private static void withLoweredCodeVolumeThreshold(Runnable action) {
|
||||
long original = ContainerLauncher.CODE_VOLUME_MIN_BYTES;
|
||||
try {
|
||||
ContainerLauncher.CODE_VOLUME_MIN_BYTES = 4 * 1024;
|
||||
action.run();
|
||||
} finally {
|
||||
ContainerLauncher.CODE_VOLUME_MIN_BYTES = original;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user