Skip to content

Commit

Permalink
mobile: Fix missing logging output in Swift integration tests (#36040)
Browse files Browse the repository at this point in the history
In Swift, `print` goes to stdout buffering. The fix is to flush the
`stdout` and `stderr` before the end of the test.

See
swiftlang/swift-corelibs-xctest#422 (comment)

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 <fredyw@google.com>
  • Loading branch information
fredyw authored Sep 9, 2024
1 parent c57ddb6 commit e41fb71
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 8 deletions.
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/CancelGRPCStreamTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/CancelStreamTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/EndToEndNetworkingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/EngineApiTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/FilterResetIdleTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/GRPCReceiveErrorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/IdleTimeoutTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/KeyValueStoreTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/ReceiveDataTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 7 additions & 3 deletions mobile/test/swift/integration/ReceiveErrorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -59,9 +66,6 @@ final class ReceiveErrorTests: XCTestCase {
.setLogger { _, msg in
print(msg, terminator: "")
}
.setLogger { _, msg in
print(msg, terminator: "")
}
.addPlatformFilter(
name: filterName,
factory: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/SendDataTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/SendHeadersTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/SendTrailersTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions mobile/test/swift/integration/SetEventTrackerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
15 changes: 10 additions & 5 deletions mobile/test/swift/integration/SetLoggerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e41fb71

Please sign in to comment.