From e41fb7185da2fef25f1a64a36d856c7c14bb28c8 Mon Sep 17 00:00:00 2001 From: Fredy Wijaya Date: Mon, 9 Sep 2024 12:44:31 -0500 Subject: [PATCH] mobile: Fix missing logging output in Swift integration tests (#36040) In Swift, `print` goes to stdout buffering. The fix is to flush the `stdout` and `stderr` before the end of the test. See https://github.com/swiftlang/swift-corelibs-xctest/issues/422#issuecomment-1310952437 Risk Level: low (tests only) Testing: CI Docs Changes: n/a Release Notes: n/a Platform Specific Features: n/a --------- Signed-off-by: Fredy Wijaya --- .../swift/integration/CancelGRPCStreamTest.swift | 7 +++++++ .../test/swift/integration/CancelStreamTest.swift | 7 +++++++ .../integration/EndToEndNetworkingTest.swift | 7 +++++++ mobile/test/swift/integration/EngineApiTest.swift | 7 +++++++ .../swift/integration/FilterResetIdleTest.swift | 7 +++++++ .../swift/integration/GRPCReceiveErrorTest.swift | 7 +++++++ .../test/swift/integration/IdleTimeoutTest.swift | 7 +++++++ .../swift/integration/KeyValueStoreTest.swift | 7 +++++++ .../test/swift/integration/ReceiveDataTest.swift | 7 +++++++ .../test/swift/integration/ReceiveErrorTest.swift | 10 +++++++--- .../integration/ResetConnectivityStateTest.swift | 7 +++++++ mobile/test/swift/integration/SendDataTest.swift | 7 +++++++ .../test/swift/integration/SendHeadersTest.swift | 7 +++++++ .../test/swift/integration/SendTrailersTest.swift | 7 +++++++ .../swift/integration/SetEventTrackerTest.swift | 7 +++++++ .../SetEventTrackerTestNoTracker.swift | 7 +++++++ mobile/test/swift/integration/SetLoggerTest.swift | 15 ++++++++++----- .../proxying/HTTPRequestUsingProxyTest.swift | 7 +++++++ 18 files changed, 129 insertions(+), 8 deletions(-) diff --git a/mobile/test/swift/integration/CancelGRPCStreamTest.swift b/mobile/test/swift/integration/CancelGRPCStreamTest.swift index b878490af6ff..6b35c002f08c 100644 --- a/mobile/test/swift/integration/CancelGRPCStreamTest.swift +++ b/mobile/test/swift/integration/CancelGRPCStreamTest.swift @@ -11,6 +11,13 @@ final class CancelGRPCStreamTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testCancelGRPCStream() { let filterName = "cancel_validation_filter" diff --git a/mobile/test/swift/integration/CancelStreamTest.swift b/mobile/test/swift/integration/CancelStreamTest.swift index e6dd2dec4e16..a53f165b2c4b 100644 --- a/mobile/test/swift/integration/CancelStreamTest.swift +++ b/mobile/test/swift/integration/CancelStreamTest.swift @@ -11,6 +11,13 @@ final class CancelStreamTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testCancelStream() { let filterName = "cancel_validation_filter" diff --git a/mobile/test/swift/integration/EndToEndNetworkingTest.swift b/mobile/test/swift/integration/EndToEndNetworkingTest.swift index 18c1e5684e62..638eefc62333 100644 --- a/mobile/test/swift/integration/EndToEndNetworkingTest.swift +++ b/mobile/test/swift/integration/EndToEndNetworkingTest.swift @@ -10,6 +10,13 @@ final class EndToEndNetworkingTest: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testNetworkRequestReturnsHeadersAndData() { EnvoyTestServer.startHttp1PlaintextServer() EnvoyTestServer.setHeadersAndData( diff --git a/mobile/test/swift/integration/EngineApiTest.swift b/mobile/test/swift/integration/EngineApiTest.swift index 669269526817..22c8a5b68868 100644 --- a/mobile/test/swift/integration/EngineApiTest.swift +++ b/mobile/test/swift/integration/EngineApiTest.swift @@ -9,6 +9,13 @@ final class EngineApiTest: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testEngineApis() throws { let engineExpectation = self.expectation(description: "Engine Running") diff --git a/mobile/test/swift/integration/FilterResetIdleTest.swift b/mobile/test/swift/integration/FilterResetIdleTest.swift index b9ed4755ba9f..da7f5a528829 100644 --- a/mobile/test/swift/integration/FilterResetIdleTest.swift +++ b/mobile/test/swift/integration/FilterResetIdleTest.swift @@ -11,6 +11,13 @@ final class FilterResetIdleTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testFilterResetIdle() { let filterName = "reset_idle_test_filter" diff --git a/mobile/test/swift/integration/GRPCReceiveErrorTest.swift b/mobile/test/swift/integration/GRPCReceiveErrorTest.swift index 6713b185eb8b..a1266db281c7 100644 --- a/mobile/test/swift/integration/GRPCReceiveErrorTest.swift +++ b/mobile/test/swift/integration/GRPCReceiveErrorTest.swift @@ -11,6 +11,13 @@ final class GRPCReceiveErrorTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testReceiveError() { let filterName = "error_validation_filter" diff --git a/mobile/test/swift/integration/IdleTimeoutTest.swift b/mobile/test/swift/integration/IdleTimeoutTest.swift index 4f3d18440f28..95324f9195cd 100644 --- a/mobile/test/swift/integration/IdleTimeoutTest.swift +++ b/mobile/test/swift/integration/IdleTimeoutTest.swift @@ -11,6 +11,13 @@ final class IdleTimeoutTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testIdleTimeout() { let filterName = "reset_idle_test_filter" diff --git a/mobile/test/swift/integration/KeyValueStoreTest.swift b/mobile/test/swift/integration/KeyValueStoreTest.swift index b33204b2c52b..595bae134513 100644 --- a/mobile/test/swift/integration/KeyValueStoreTest.swift +++ b/mobile/test/swift/integration/KeyValueStoreTest.swift @@ -11,6 +11,13 @@ final class KeyValueStoreTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testKeyValueStore() { // swiftlint:disable:next line_length let kvStoreType = "type.googleapis.com/envoymobile.extensions.filters.http.test_kv_store.TestKeyValueStore" diff --git a/mobile/test/swift/integration/ReceiveDataTest.swift b/mobile/test/swift/integration/ReceiveDataTest.swift index 2e2855535508..483c947e7261 100644 --- a/mobile/test/swift/integration/ReceiveDataTest.swift +++ b/mobile/test/swift/integration/ReceiveDataTest.swift @@ -11,6 +11,13 @@ final class ReceiveDataTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testReceiveData() { let directResponseBody = "response_body" EnvoyTestServer.startHttp1PlaintextServer() diff --git a/mobile/test/swift/integration/ReceiveErrorTest.swift b/mobile/test/swift/integration/ReceiveErrorTest.swift index 24d9a2b0b194..cb8b408adcc6 100644 --- a/mobile/test/swift/integration/ReceiveErrorTest.swift +++ b/mobile/test/swift/integration/ReceiveErrorTest.swift @@ -10,6 +10,13 @@ final class ReceiveErrorTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testReceiveError() { let filterName = "error_validation_filter" @@ -59,9 +66,6 @@ final class ReceiveErrorTests: XCTestCase { .setLogger { _, msg in print(msg, terminator: "") } - .setLogger { _, msg in - print(msg, terminator: "") - } .addPlatformFilter( name: filterName, factory: { diff --git a/mobile/test/swift/integration/ResetConnectivityStateTest.swift b/mobile/test/swift/integration/ResetConnectivityStateTest.swift index e0c260feb690..ddeb5bb0590e 100644 --- a/mobile/test/swift/integration/ResetConnectivityStateTest.swift +++ b/mobile/test/swift/integration/ResetConnectivityStateTest.swift @@ -11,6 +11,13 @@ final class ResetConnectivityStateTest: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testResetConnectivityState() { EnvoyTestServer.startHttp1PlaintextServer() diff --git a/mobile/test/swift/integration/SendDataTest.swift b/mobile/test/swift/integration/SendDataTest.swift index 25c096e61a94..4a7b736b6f1a 100644 --- a/mobile/test/swift/integration/SendDataTest.swift +++ b/mobile/test/swift/integration/SendDataTest.swift @@ -11,6 +11,13 @@ final class SendDataTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testSendData() throws { EnvoyTestServer.startHttp1PlaintextServer() EnvoyTestServer.setHeadersAndData("x-response-foo", header_value: "aaa", response_body: "data") diff --git a/mobile/test/swift/integration/SendHeadersTest.swift b/mobile/test/swift/integration/SendHeadersTest.swift index 6b5bc67fce73..46de840b92ef 100644 --- a/mobile/test/swift/integration/SendHeadersTest.swift +++ b/mobile/test/swift/integration/SendHeadersTest.swift @@ -11,6 +11,13 @@ final class SendHeadersTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testSendHeaders() { EnvoyTestServer.startHttp1PlaintextServer() diff --git a/mobile/test/swift/integration/SendTrailersTest.swift b/mobile/test/swift/integration/SendTrailersTest.swift index e557756c0edb..5f1caa7a2404 100644 --- a/mobile/test/swift/integration/SendTrailersTest.swift +++ b/mobile/test/swift/integration/SendTrailersTest.swift @@ -11,6 +11,13 @@ final class SendTrailersTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testSendTrailers() throws { // swiftlint:disable:next line_length let assertionFilterType = "type.googleapis.com/envoymobile.extensions.filters.http.assertion.Assertion" diff --git a/mobile/test/swift/integration/SetEventTrackerTest.swift b/mobile/test/swift/integration/SetEventTrackerTest.swift index a13e0ddfed56..beec655a1717 100644 --- a/mobile/test/swift/integration/SetEventTrackerTest.swift +++ b/mobile/test/swift/integration/SetEventTrackerTest.swift @@ -11,6 +11,13 @@ final class SetEventTrackerTest: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testSetEventTracker() throws { EnvoyTestServer.startHttp1PlaintextServer() diff --git a/mobile/test/swift/integration/SetEventTrackerTestNoTracker.swift b/mobile/test/swift/integration/SetEventTrackerTestNoTracker.swift index 78449f41f1e0..33f5035191e0 100644 --- a/mobile/test/swift/integration/SetEventTrackerTestNoTracker.swift +++ b/mobile/test/swift/integration/SetEventTrackerTestNoTracker.swift @@ -11,6 +11,13 @@ final class SetEventTrackerTestNoTracker: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testEmitEventWithoutSettingEventTracker() throws { EnvoyTestServer.startHttp1PlaintextServer() diff --git a/mobile/test/swift/integration/SetLoggerTest.swift b/mobile/test/swift/integration/SetLoggerTest.swift index afe3a8a1654c..96836ebf9dd0 100644 --- a/mobile/test/swift/integration/SetLoggerTest.swift +++ b/mobile/test/swift/integration/SetLoggerTest.swift @@ -11,6 +11,13 @@ final class LoggerTests: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + func testSetLogger() throws { let engineExpectation = self.expectation(description: "Run started engine") let loggingExpectation = self.expectation(description: "Run used platform logger") @@ -24,16 +31,14 @@ final class LoggerTests: XCTestCase { .setLogLevel(.debug) .setLogger { _, msg in print(msg, terminator: "") + if msg.contains("starting main dispatch loop") { + loggingExpectation.fulfill() + } } .addNativeFilter( name: "test_logger", // swiftlint:disable:next line_length typedConfig: "[type.googleapis.com/envoymobile.extensions.filters.http.test_logger.TestLogger]{}") - .setLogger { _, msg in - if msg.contains("starting main dispatch loop") { - loggingExpectation.fulfill() - } - } .setOnEngineRunning { engineExpectation.fulfill() } diff --git a/mobile/test/swift/integration/proxying/HTTPRequestUsingProxyTest.swift b/mobile/test/swift/integration/proxying/HTTPRequestUsingProxyTest.swift index da80194d2ff3..67f3e215bb3f 100644 --- a/mobile/test/swift/integration/proxying/HTTPRequestUsingProxyTest.swift +++ b/mobile/test/swift/integration/proxying/HTTPRequestUsingProxyTest.swift @@ -12,6 +12,13 @@ final class HTTPRequestUsingProxyTest: XCTestCase { register_test_extensions() } + override static func tearDown() { + super.tearDown() + // Flush the stdout and stderror to show the print output. + fflush(stdout) + fflush(stderr) + } + private func executeRequest(engine: Engine, scheme: String, authority: String) -> String? { let responseHeadersExpectation = self.expectation(description: "Successful response headers received")