From 6b494ddf95de280bafc0613f10f8d6f50f1c1c4a Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Mon, 29 Sep 2025 12:32:37 +0200 Subject: [PATCH] Flush logs at the end of test execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise it sometimes happens that shutdown and other messages are logged during the next test’s execution, which makes it harder to diagnose issues. --- Sources/SKTestSupport/TestSourceKitLSPClient.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/SKTestSupport/TestSourceKitLSPClient.swift b/Sources/SKTestSupport/TestSourceKitLSPClient.swift index 0f6434697..8365d02b5 100644 --- a/Sources/SKTestSupport/TestSourceKitLSPClient.swift +++ b/Sources/SKTestSupport/TestSourceKitLSPClient.swift @@ -15,6 +15,7 @@ import InProcessClient package import LanguageServerProtocol import LanguageServerProtocolExtensions import LanguageServerProtocolJSONRPC +import SKLogging package import SKOptions import SKUtilities import SourceKitD @@ -217,14 +218,21 @@ package final class TestSourceKitLSPClient: MessageHandler, Sendable { deinit { // It's really unfortunate that there are no async deinits. If we had async // deinits, we could await the sending of a ShutdownRequest. - let sema = WrappedSemaphore(name: "Shutdown") + let shutdownSemaphore = WrappedSemaphore(name: "Shutdown") server.handle(ShutdownRequest(), id: .number(Int(nextRequestID.fetchAndIncrement()))) { result in - sema.signal() + shutdownSemaphore.signal() } - sema.waitOrXCTFail() + shutdownSemaphore.waitOrXCTFail() self.send(ExitNotification()) cleanUp() + + let flushSemaphore = WrappedSemaphore(name: "Flush log") + Task { + await NonDarwinLogger.flush() + flushSemaphore.signal() + } + flushSemaphore.waitOrXCTFail() } // MARK: - Sending messages