swift-server/swift-service-lifecycle

`Lifecycle.wait()` hangs in tests

MahdiBM opened this issue · 1 comments

I've just moved Vapor's Penny bot to use swift-service-lifecycle (here).

What happens is, if I use await Penny.main() in tests (here), the test reaches the ServiceLifecycle.wait() call, but hangs there (Penny type is the @main entry point).

Using ServiceLifecycle.wait() when running the executable works as expected.

Optimally this shouldn't happen and tests should run without hanging. Before this change, we were using RunLoop.main.run() to stop the executable from exiting immediately (with a non-async main()) and this was working fine with tests.

The solution i've found is to not call ServiceLifecycle.wait() at all in tests. As you can see, the tests call another await Penny.start() function which is the same as await Penny.main(), except that it doesn't call ServiceLifecycle.wait().

Environment:

swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Darwin MahdiBM-Macbook.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64

with swift-service-lifecycle alpha.11.

Going to close this issue since the new implementation doesn't use blocking operations anymore but rather Swift Concurrency.