mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
1 parent
3dee17e51d
commit
438ae619fd
5 files changed
+86
-15
No files matched your search
+24
@@ -94,6 +94,30 @@ class LambdaExecutorServiceTest {
|
||||
assertNull(result.getFunctionError());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resultAfterConfiguredDeadline_timesOutAndDestroysHandle() {
|
||||
RuntimeApiServer rtas = mock(RuntimeApiServer.class);
|
||||
ContainerHandle handle = new ContainerHandle("cid-late", "test-fn", rtas, ContainerState.WARM);
|
||||
|
||||
when(warmPool.acquire(any())).thenReturn(handle);
|
||||
doAnswer(inv -> {
|
||||
PendingInvocation pi = inv.getArgument(0);
|
||||
pi.prepareForDispatch();
|
||||
pi.markDispatched();
|
||||
CompletableFuture.delayedExecutor(1200, TimeUnit.MILLISECONDS)
|
||||
.execute(() -> pi.getResultFuture().complete(
|
||||
new InvokeResult(200, null, "{\"ok\":true}".getBytes(), null, "req-late")));
|
||||
return pi.getResultFuture();
|
||||
}).when(rtas).enqueue(any(PendingInvocation.class));
|
||||
|
||||
InvokeResult result = executor.invoke(fn, "{}".getBytes(), InvocationType.RequestResponse);
|
||||
|
||||
verify(warmPool).destroyHandle(handle);
|
||||
verify(warmPool, never()).release(handle);
|
||||
assertEquals("Unhandled", result.getFunctionError());
|
||||
assertTrue(new String(result.getPayload()).contains("Function.TimedOut"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void timeoutResponse_containsCorrectErrorPayload() {
|
||||
fn.setTimeout(2);
|
||||
|
||||
+24
-1
@@ -109,6 +109,29 @@ class RuntimeApiServerTest {
|
||||
assertTrue(response.body().contains("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(10)
|
||||
void nextEndpoint_startsDeadlineWhenInvocationIsDispatched() throws Exception {
|
||||
long queuedDeadline = System.currentTimeMillis() + 1_000;
|
||||
PendingInvocation invocation = new PendingInvocation(
|
||||
"req-deadline", "{}".getBytes(), queuedDeadline,
|
||||
"arn:aws:lambda:us-east-1:000000000000:function:test",
|
||||
new CompletableFuture<>());
|
||||
server.enqueue(invocation);
|
||||
|
||||
Thread.sleep(300);
|
||||
HttpResponse<String> response = httpClient.send(HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://localhost:" + port
|
||||
+ "/2018-06-01/runtime/invocation/next"))
|
||||
.GET().build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
long advertisedDeadline = Long.parseLong(response.headers()
|
||||
.firstValue("Lambda-Runtime-Deadline-Ms").orElseThrow());
|
||||
assertTrue(advertisedDeadline >= queuedDeadline + 200,
|
||||
"queueing and cold-start time must not consume the handler timeout");
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression: an Invoke with no body (e.g. {@code aws lambda invoke} without
|
||||
* {@code --payload}) reaches the /next handler as a {@code byte[0]}, not
|
||||
@@ -2067,4 +2090,4 @@ class RuntimeApiServerTest {
|
||||
}
|
||||
return server.isExtensionParked(extensionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user