Skip to content

Commit

Permalink
mobile: switching idle timeout test to full network stack (envoyproxy…
Browse files Browse the repository at this point in the history
…#30667)

Changing a test to use a fake upstream and time out sending the request.  This allows us to compile away the listener for this build

Risk Level: n/a (test only)
Testing: yes
Docs Changes: no

Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored Nov 6, 2023
1 parent 29ddf84 commit 2970ddb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 85 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/mobile-ios_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ jobs:
- name: 'Run swift library tests'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# runs with the listener enabled due to IdleTimeoutTest not setting up a test backend.
run: |
cd mobile
./bazelw test \
--experimental_ui_max_stdouterr_bytes=10485760 \
--config=ios \
--define envoy_mobile_listener=enabled \
--build_tests_only \
--config=mobile-remote-ci-macos \
//test/swift/...
Expand Down
1 change: 1 addition & 0 deletions mobile/test/swift/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ envoy_mobile_swift_test(
deps = [
":test_extensions",
"//library/objective-c:envoy_engine_objc_lib",
"//test/objective-c:envoy_test_server",
],
)

Expand Down
97 changes: 14 additions & 83 deletions mobile/test/swift/integration/IdleTimeoutTest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Envoy
import EnvoyEngine
import EnvoyTestServer
import Foundation
import TestExtensions
import XCTest
Expand All @@ -11,83 +12,7 @@ final class IdleTimeoutTests: XCTestCase {
}

func testIdleTimeout() {
let idleTimeout = "0.5s"
let remotePort = Int.random(in: 10001...11000)
// swiftlint:disable:next line_length
let hcmType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
// swiftlint:disable:next line_length
let emhcmType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.EnvoyMobileHttpConnectionManager"
let pbfType =
"type.googleapis.com/envoymobile.extensions.filters.http.platform_bridge.PlatformBridge"
let localErrorFilterType =
"type.googleapis.com/envoymobile.extensions.filters.http.local_error.LocalError"
let filterName = "reset_idle_test_filter"
let config =
"""
static_resources:
listeners:
- name: fake_remote_listener
address:
socket_address: { protocol: TCP, address: 127.0.0.1, port_value: \(remotePort) }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": \(hcmType)
stat_prefix: remote_hcm
route_config:
name: remote_route
virtual_hosts:
- name: remote_service
domains: ["*"]
routes:
- match: { prefix: "/" }
direct_response: { status: 200 }
http_filters:
- name: envoy.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
- name: base_api_listener
address:
socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }
api_listener:
api_listener:
"@type": \(emhcmType)
config:
stat_prefix: api_hcm
stream_idle_timeout: \(idleTimeout)
route_config:
name: api_router
virtual_hosts:
- name: api
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: fake_remote }
http_filters:
- name: envoy.filters.http.platform_bridge
typed_config:
"@type": \(pbfType)
platform_filter_name: \(filterName)
- name: envoy.filters.http.local_error
typed_config:
"@type": \(localErrorFilterType)
- name: envoy.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: fake_remote
connect_timeout: 0.25s
type: STATIC
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: fake_remote
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address: { address: 127.0.0.1, port_value: \(remotePort) }
"""

class IdleTimeoutValidationFilter: AsyncResponseFilter, ResponseFilter {
let timeoutExpectation: XCTestExpectation
Expand Down Expand Up @@ -132,7 +57,7 @@ static_resources:
}

func onError(_ error: EnvoyError, streamIntel: FinalStreamIntel) {
XCTAssertEqual(error.errorCode, 0)
XCTAssertEqual(error.errorCode, 4)
timeoutExpectation.fulfill()
}

Expand All @@ -147,8 +72,11 @@ static_resources:
let callbackExpectation =
self.expectation(description: "Stream idle timeout received by callbacks")

let engine = EngineBuilder(yaml: config)
EnvoyTestServer.startHttp1PlaintextServer()

let engine = EngineBuilder()
.addLogLevel(.trace)
.addStreamIdleTimeoutSeconds(1)
.addPlatformFilter(
name: filterName,
factory: { IdleTimeoutValidationFilter(timeoutExpectation: filterExpectation) }
Expand All @@ -157,27 +85,30 @@ static_resources:

let client = engine.streamClient()

let requestHeaders = RequestHeadersBuilder(method: .get, scheme: "https",
authority: "example.com", path: "/test")
.build()
let port = String(EnvoyTestServer.getEnvoyPort())
let requestHeaders = RequestHeadersBuilder(
method: .get, scheme: "http", authority: "localhost:" + port, path: "/"
)
.build()

client
.newStreamPrototype()
.setOnError { error, _ in
XCTAssertEqual(error.errorCode, 0)
XCTAssertEqual(error.errorCode, 4)
callbackExpectation.fulfill()
}
.setOnCancel { _ in
XCTFail("Unexpected call to onCancel filter callback")
}
.start()
.sendHeaders(requestHeaders, endStream: true)
.sendHeaders(requestHeaders, endStream: false)

XCTAssertEqual(
XCTWaiter.wait(for: [filterExpectation, callbackExpectation], timeout: 10),
.completed
)

engine.terminate()
EnvoyTestServer.shutdownTestServer()
}
}

0 comments on commit 2970ddb

Please sign in to comment.