-
Notifications
You must be signed in to change notification settings - Fork 85
engine: add drainConnections API to platform layer #1731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d102879
engine: expose drainConnections API at the platform level
c511040
all the way up
4baa22c
tests
9d94493
fix
be7178d
swiftlint
1751385
Merge branch 'main' into engine-drain-API
bd59a2a
Merge branch 'engine-drain-API' of github.com:lyft/envoy-mobile into …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,4 +91,6 @@ extension MockEnvoyEngine: EnvoyEngine { | |
| } | ||
|
|
||
| func terminate() {} | ||
|
|
||
| func drainConnections() {} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package test.kotlin.integration | ||
|
|
||
| import io.envoyproxy.envoymobile.Custom | ||
| import io.envoyproxy.envoymobile.EngineBuilder | ||
| import io.envoyproxy.envoymobile.RequestHeadersBuilder | ||
| import io.envoyproxy.envoymobile.RequestMethod | ||
| import io.envoyproxy.envoymobile.ResponseHeaders | ||
| import io.envoyproxy.envoymobile.UpstreamHttpProtocol | ||
| import io.envoyproxy.envoymobile.engine.JniLibrary | ||
| import java.util.concurrent.CountDownLatch | ||
| import java.util.concurrent.TimeUnit | ||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.assertj.core.api.Assertions.fail | ||
| import org.junit.Test | ||
|
|
||
| private val apiListenerType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.EnvoyMobileHttpConnectionManager" | ||
| private val assertionFilterType = "type.googleapis.com/envoymobile.extensions.filters.http.assertion.Assertion" | ||
| private val config = | ||
| """ | ||
| static_resources: | ||
| listeners: | ||
| - name: base_api_listener | ||
| address: | ||
| socket_address: | ||
| protocol: TCP | ||
| address: 0.0.0.0 | ||
| port_value: 10000 | ||
| api_listener: | ||
| api_listener: | ||
| "@type": $apiListenerType | ||
| config: | ||
| stat_prefix: hcm | ||
| route_config: | ||
| name: api_router | ||
| virtual_hosts: | ||
| - name: api | ||
| domains: | ||
| - "*" | ||
| routes: | ||
| - match: | ||
| prefix: "/" | ||
| direct_response: | ||
| status: 200 | ||
| http_filters: | ||
| - name: envoy.filters.http.assertion | ||
| typed_config: | ||
| "@type": $assertionFilterType | ||
| match_config: | ||
| http_request_headers_match: | ||
| headers: | ||
| - name: ":authority" | ||
| exact_match: example.com | ||
| - name: envoy.router | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router | ||
| """ | ||
|
|
||
| class DrainConnectionsTest { | ||
|
|
||
| init { | ||
| JniLibrary.loadTestLibrary() | ||
| } | ||
|
|
||
| @Test | ||
| fun `successful request after connection drain`() { | ||
| val headersExpectation = CountDownLatch(2) | ||
|
|
||
| val engine = EngineBuilder(Custom(config)).build() | ||
| val client = engine.streamClient() | ||
|
|
||
| val requestHeaders = RequestHeadersBuilder( | ||
| method = RequestMethod.GET, | ||
| scheme = "https", | ||
| authority = "example.com", | ||
| path = "/test" | ||
| ) | ||
| .addUpstreamHttpProtocol(UpstreamHttpProtocol.HTTP2) | ||
| .build() | ||
|
|
||
| var resultHeaders1: ResponseHeaders? = null | ||
| var resultEndStream1: Boolean? = null | ||
| client.newStreamPrototype() | ||
| .setOnResponseHeaders { responseHeaders, endStream, _ -> | ||
| resultHeaders1 = responseHeaders | ||
| resultEndStream1 = endStream | ||
| headersExpectation.countDown() | ||
| } | ||
| .setOnError { _, _ -> fail("Unexpected error") } | ||
| .start() | ||
| .sendHeaders(requestHeaders, true) | ||
|
|
||
| headersExpectation.await(10, TimeUnit.SECONDS) | ||
|
|
||
| engine.drainConnections() | ||
|
|
||
| var resultHeaders2: ResponseHeaders? = null | ||
| var resultEndStream2: Boolean? = null | ||
| client.newStreamPrototype() | ||
| .setOnResponseHeaders { responseHeaders, endStream, _ -> | ||
| resultHeaders2 = responseHeaders | ||
| resultEndStream2 = endStream | ||
| headersExpectation.countDown() | ||
| } | ||
| .setOnError { _, _ -> fail("Unexpected error") } | ||
| .start() | ||
| .sendHeaders(requestHeaders, true) | ||
|
|
||
| headersExpectation.await(10, TimeUnit.SECONDS) | ||
|
|
||
| engine.terminate() | ||
|
|
||
| assertThat(headersExpectation.count).isEqualTo(0) | ||
| assertThat(resultHeaders1!!.httpStatus).isEqualTo(200) | ||
| assertThat(resultEndStream1).isTrue() | ||
| assertThat(resultHeaders2!!.httpStatus).isEqualTo(200) | ||
| assertThat(resultEndStream2).isTrue() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import Envoy | ||
| import EnvoyEngine | ||
| import Foundation | ||
| import XCTest | ||
|
|
||
| final class DrainConnectionsTest: XCTestCase { | ||
| func testDrainConnections() { | ||
| // swiftlint:disable:next line_length | ||
| let emhcmType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.EnvoyMobileHttpConnectionManager" | ||
| // swiftlint:disable:next line_length | ||
| let assertionFilterType = "type.googleapis.com/envoymobile.extensions.filters.http.assertion.Assertion" | ||
| let config = | ||
| """ | ||
| static_resources: | ||
| listeners: | ||
| - 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: hcm | ||
| route_config: | ||
| name: api_router | ||
| virtual_hosts: | ||
| - name: api | ||
| domains: | ||
| - "*" | ||
| routes: | ||
| - match: | ||
| prefix: "/" | ||
| direct_response: | ||
| status: 200 | ||
| http_filters: | ||
| - name: envoy.filters.http.assertion | ||
| typed_config: | ||
| "@type": \(assertionFilterType) | ||
| match_config: | ||
| http_request_headers_match: | ||
| headers: | ||
| - name: ":authority" | ||
| exact_match: example.com | ||
| - name: envoy.router | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router | ||
| """ | ||
| let engine = EngineBuilder(yaml: config) | ||
| .addLogLevel(.debug) | ||
| .build() | ||
|
|
||
| let client = engine | ||
| .streamClient() | ||
|
|
||
| let requestHeaders = RequestHeadersBuilder(method: .get, scheme: "https", | ||
| authority: "example.com", path: "/test") | ||
| .addUpstreamHttpProtocol(.http2) | ||
| .build() | ||
|
|
||
| let expectation1 = self.expectation(description: "Run called with expected http status first request") | ||
| client | ||
| .newStreamPrototype() | ||
| .setOnResponseHeaders { responseHeaders, endStream, _ in | ||
| XCTAssertEqual(200, responseHeaders.httpStatus) | ||
| XCTAssertTrue(endStream) | ||
| expectation1.fulfill() | ||
| } | ||
| .setOnError { _, _ in | ||
| XCTFail("Unexpected error") | ||
| } | ||
| .start() | ||
| .sendHeaders(requestHeaders, endStream: true) | ||
|
|
||
| XCTAssertEqual(XCTWaiter.wait(for: [expectation1], timeout: 1), .completed) | ||
|
|
||
| engine.drainConnections() | ||
|
|
||
| let expectation2 = self.expectation(description: "Run called with expected http status first request") | ||
|
junr03 marked this conversation as resolved.
Outdated
|
||
| client | ||
| .newStreamPrototype() | ||
| .setOnResponseHeaders { responseHeaders, endStream, _ in | ||
| XCTAssertEqual(200, responseHeaders.httpStatus) | ||
| XCTAssertTrue(endStream) | ||
| expectation2.fulfill() | ||
| } | ||
| .setOnError { _, _ in | ||
| XCTFail("Unexpected error") | ||
| } | ||
| .start() | ||
| .sendHeaders(requestHeaders, endStream: true) | ||
|
|
||
| XCTAssertEqual(XCTWaiter.wait(for: [expectation2], timeout: 1), .completed) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.