Files
swift-aws-lambda-runtime/Tests/AWSLambdaRuntimeTests
Sébastien Stormacq b1553d2766 Accept multiple POST /invoke requests to allow parallel testing (#585)
Closing
https://github.com/swift-server/swift-aws-lambda-runtime/issues/584

The LocalServer now queues concurrent `POST /invoke` requests from
testing client applications and ensures that the requests are delivered
to the Lambda Runtime one by one, just like the AWS Lambda Runtime
environment does.

The `Pool` has now two modes : pure FIFO (one element get exactly one
`next()`) and one mode where multiple elements can get pushed and
multiple `next(for requestId:String)` can be called concurrently.

The two modes are needed because invocations are 1:1 (one `POST /invoke`
is always by one matching `GET /next`) but responses are n:n (a response
can have multiple chunks and concurrent invocations can trigger multiple
`next(for requestId: String)`

I made a couple of additional changes while working on this PR 

- I moved the `Pool` code in a separate file for improved readability 

- I removed an instance of `DispatchTime` that was hiding in the code,
unnoticed until today

- I removed the `async` requirement on `Pool.push(_)` function. This was
not required (thank you @t089 for having reported this)

- I removed the `fatalError()` that was in the `Pool` implementation.
The pool now throws an error when `next()` is invoked concurrently,
making it easier to test.

- I added extensive unit tests to validate the Pool behavior 

- I added a test to verify that a rapid succession of client invocations
are correctly queued and return no error

- I moved a `continuation(resume:)` outside of a lock. Generally
speaking, it's a bad idea to resume continuation while owning a lock. I
suspect this is causing a error during test execution when we spawn and
tear down mutliple `Task` very quickly. In some rare occasions, the test
was failing with an invalid assertion in NIO :
`NIOCore/NIOAsyncWriter.swift:177: Fatal error: Deinited NIOAsyncWriter
without calling finish()`

---------

Co-authored-by: Sebastien Stormacq <stormacq@amazon.lu>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-22 07:52:31 +02:00
..