How to serialize tests suites?

I'm working on the Swift Lambda Runtime project and some of our tests involve spanning a local HTTP server. The tests reside in different test suites.

I want to avoid port conflicts when the tests are run in paralel.

I know we can serialize tests in a single suite with the .serialized trait. Can we serialize suites as well ?

See this PR for more context add support for LOCAL_LAMBDA_PORT by sebsto · Pull Request #557 · swift-server/swift-aws-lambda-runtime · GitHub

Apologies, this is not an answer to your actual question. But in general, I'd suggest to make them runnable in parallel. SwiftNIO supports passing port 0 meaning "find a random free port" which is what NIO and most other stuff does in its test suites. That means you can easily run one fresh server per test case; the test cases would just interrogate the server about "what port should I use for this test?".

1 Like

Thank you Johannes. This is a good point. The challenge here is we need to spwan a mock server and then tell the Lambda Runtime Client where to connect to.
Having a fixed port number helped. Otherwise, I need to figure out a way to report the actual port number to the client.

So far, we never had a conflict, even when executing the test in parallel. But i want to play it future-proof and safe.

After double checking the code, this is What Fabian already do.

See swift-aws-lambda-runtime/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift at ec28c9669684bbbe22e447b24c201add4480e8b0 · swift-server/swift-aws-lambda-runtime · GitHub

So the mock server uses port 0 to bind to any available port.

Problem solved :-)

2 Likes