Skip to content

Commit

Permalink
mobile: Fix the flaky SendDataTest
Browse files Browse the repository at this point in the history
The test failed when adding the native Assertion filter, with an error
from loadFromYaml: INVALID_ARGUMENT: could not find @type
'type.googleapis.com/envoymobile.extensions.filters.http.assertion.Assertion

After running git bisect, it turns out the bad commit came from
envoyproxy#33169. That PR introduces
HttpTestServer to the SendDataTest.kt, which causes the required proto
types to not get loaded.

In this commit, the test is fixed by using a TestRemoteResponse filter,
similar to the other Kotlin tests (e.g. SendTrailersTest). However, we
need to figure out why the config filter protos aren't loading when
creating the HttpTestServer.

Signed-off-by: Ali Beyad <abeyad@google.com>
  • Loading branch information
abeyad committed Mar 30, 2024
1 parent 29117db commit 7763cfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
1 change: 1 addition & 0 deletions mobile/test/jni/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cc_library(
"//library/jni:envoy_jni_lib",
"@envoy_build_config//:test_extensions",
],
alwayslink = True,
)

# Library which contains all the JNI related targets.
Expand Down
4 changes: 1 addition & 3 deletions mobile/test/kotlin/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ envoy_mobile_jni_kt_test(
],
)

envoy_mobile_android_test(
envoy_mobile_jni_kt_test(
name = "send_data_test",
srcs = [
"SendDataTest.kt",
Expand All @@ -254,8 +254,6 @@ envoy_mobile_android_test(
native_lib_name = "envoy_jni_with_test_extensions",
deps = [
"//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib",
"//test/java/io/envoyproxy/envoymobile/engine/testing",
"//test/java/io/envoyproxy/envoymobile/engine/testing:http_test_server_factory_lib",
],
)

Expand Down
26 changes: 7 additions & 19 deletions mobile/test/kotlin/integration/SendDataTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import io.envoyproxy.envoymobile.EngineBuilder
import io.envoyproxy.envoymobile.RequestHeadersBuilder
import io.envoyproxy.envoymobile.RequestMethod
import io.envoyproxy.envoymobile.Standard
import io.envoyproxy.envoymobile.engine.AndroidJniLibrary
import io.envoyproxy.envoymobile.engine.EnvoyConfiguration.TrustChainVerification
import io.envoyproxy.envoymobile.engine.JniLibrary
import io.envoyproxy.envoymobile.engine.testing.HttpTestServerFactory
import io.envoyproxy.envoymobile.engine.testing.HttpTestServerFactory.HttpTestServer
import java.nio.ByteBuffer
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
Expand All @@ -20,24 +17,14 @@ import org.junit.Test

private const val ASSERTION_FILTER_TYPE =
"type.googleapis.com/envoymobile.extensions.filters.http.assertion.Assertion"
private const val TEST_RESPONSE_FILTER_TYPE =
"type.googleapis.com/envoymobile.extensions.filters.http.test_remote_response.TestRemoteResponse"
private const val REQUEST_STRING_MATCH = "match_me"

// TODO(fredyw): Figure out why HttpTestServer prevents EngineBuilder from using native filters.
class SendDataTest {
init {
AndroidJniLibrary.loadTestLibrary()
JniLibrary.load()
}

private lateinit var httpTestServer: HttpTestServer

@Before
fun setUp() {
httpTestServer = HttpTestServerFactory.start(HttpTestServerFactory.Type.HTTP2_WITH_TLS)
}

@After
fun tearDown() {
httpTestServer.shutdown()
JniLibrary.loadTestLibrary()
}

@Test
Expand All @@ -49,6 +36,7 @@ class SendDataTest {
"envoy.filters.http.assertion",
"{'@type': $ASSERTION_FILTER_TYPE, match_config: {http_request_generic_body_match: {patterns: [{string_match: $REQUEST_STRING_MATCH}]}}}"
)
.addNativeFilter("test_remote_response", "{'@type': $TEST_RESPONSE_FILTER_TYPE}")
.setTrustChainVerification(TrustChainVerification.ACCEPT_UNTRUSTED)
.build()

Expand All @@ -58,8 +46,8 @@ class SendDataTest {
RequestHeadersBuilder(
method = RequestMethod.GET,
scheme = "https",
authority = "localhost:${httpTestServer.port}",
path = "/simple.txt"
authority = "example.com",
path = "/test"
)
.build()

Expand Down

0 comments on commit 7763cfb

Please sign in to comment.