fix(lambda): restore create-copy-start ordering for provided runtimes (#524)

* fix(lambda): restore create-copy-start ordering for provided runtimes

The refactor in #466 changed ContainerLauncher from create → copy →
start to createAndStart → copy, breaking provided.* runtimes whose
entrypoint execs /var/runtime/bootstrap immediately on start — before
the file has been copied in.

Split ContainerLifecycleManager into create(spec) and
startCreated(containerId, spec) so ContainerLauncher can copy code and
the bootstrap file into the container filesystem before starting it.
Other services (ECS, ECR, EKS, MSK, ElastiCache, RDS) continue using
createAndStart since they have no pre-start file copy requirement.

Fixes #494

* test(lambda): verify create-copy-start ordering for provided runtimes

Update ContainerLauncherTest to use the new create/startCreated API
and add two ordering tests:

- launchFunction_createsBeforeCopyAndStartsAfter: verifies the
  create → copy → startCreated sequence for any runtime using
  Mockito InOrder.
- launchProvidedRuntime_copiesBootstrapBeforeStart: verifies the same
  ordering specifically for provided.al2023 with a bootstrap file,
  and asserts createAndStart is never called. This is the exact
  regression from #466 that caused exit 127.

* refactor: delegate createAndStart to create + startCreated

Eliminate duplicated container-creation logic by making createAndStart
a thin delegate to create(spec) + startCreated(containerId, spec).
Future fixes to either step now apply to both call paths automatically.

* test(lambda): add SDK compatibility test for provided runtime invoke

Create and invoke a provided.al2023 function using the shell-based
bootstrap from LambdaUtils.providedRuntimeZip(). Asserts the response
contains the expected payload without timeout or FunctionError.

This test fails on 1.5.4 (Read timed out after 120s due to the
create-start ordering regression in #466) and passes on the fix.

* docs: add @param to create() and rename misleading test

- Add missing @param spec tag to ContainerLifecycleManager.create()
  for consistency with surrounding methods.
- Rename launchFunctionCopiesCode to launchFunction_createsWithoutBindMounts
  to reflect what the test actually asserts. Remove the getDockerClient
  verify that didn't prove code copying.

* test(lambda): stub Docker copy chain and add cleanup for provided runtime test

- Stub dockerClient.copyArchiveToContainerCmd → withRemotePath →
  withTarInputStream so copy operations execute against the mock
  instead of throwing silently. Ordering tests now verify actual
  Docker copy invocations between create and startCreated.
- Provided runtime test asserts both /var/task and /var/runtime
  remote paths were targeted.
- Add sdk-test-provided-fn to @AfterAll cleanup in LambdaTest so
  assertion failures don't leak the function across test runs.

* test(lambda): drain tar InputStream in copy mock to prevent thread leaks

Each copy mock now returns a fresh CopyArchiveToContainerCmd that
drains the PipedInputStream on exec(), so the background tar writer
thread can complete instead of blocking when the pipe buffer fills.
Remote paths are captured via the mock's withRemotePath answer and
asserted from the shared list.

Also adds sdk-test-provided-fn to @AfterAll cleanup in the compat
test to prevent function leaks on assertion failure.

* refactor(lambda): drop unused ContainerInfo variable from launch

The return value of startCreated() was assigned but never read.
Remove the variable and its now-unused import.

* test(lambda): include getDockerClient in InOrder verification

Add the getDockerClient() call between create() and
copyArchiveToContainerCmd() in both ordering tests so the verified
sequence matches the actual call flow in ContainerLauncher.launch().

* style: remove redundant doAnswer import

The wildcard import already covers it.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-04-19 09:33:54 -05:00
1 parent b37f4c71e0
commit bc951bf4bf
4 files changed
+168 -33

No files matched your search

@@ -33,6 +33,10 @@ class LambdaTest {
lambda.deleteFunction(DeleteFunctionRequest.builder()
.functionName("sdk-test-ruby-fn").build());
} catch (Exception ignored) {}
try {
lambda.deleteFunction(DeleteFunctionRequest.builder()
.functionName("sdk-test-provided-fn").build());
} catch (Exception ignored) {}
lambda.close();
}
}
@@ -306,6 +310,40 @@ class LambdaTest {
@Test
@Order(17)
void providedRuntimeInvoke() {
String providedFn = "sdk-test-provided-fn";
lambda.createFunction(CreateFunctionRequest.builder()
.functionName(providedFn)
.runtime(Runtime.PROVIDED_AL2023)
.role(ROLE)
.handler("bootstrap")
.timeout(30)
.code(FunctionCode.builder()
.zipFile(SdkBytes.fromByteArray(LambdaUtils.providedRuntimeZip()))
.build())
.build());
// RequestResponse invoke — the bootstrap shell script POSTs a
// response via the Runtime API, so we should get a real payload
// back rather than a timeout.
InvokeResponse response = lambda.invoke(InvokeRequest.builder()
.functionName(providedFn)
.invocationType(InvocationType.REQUEST_RESPONSE)
.payload(SdkBytes.fromUtf8String("{\"test\":true}"))
.build());
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.functionError()).isNull();
String payload = response.payload().asUtf8String();
assertThat(payload).contains("hello from provided runtime");
lambda.deleteFunction(DeleteFunctionRequest.builder()
.functionName(providedFn).build());
}
@Test
@Order(18)
void rubyRuntimeSupport() {
String rubyFn = "sdk-test-ruby-fn";