diff --git a/bazel/WASM.md b/bazel/WASM.md index df717e59d512d..4f0f0f4179776 100644 --- a/bazel/WASM.md +++ b/bazel/WASM.md @@ -3,5 +3,17 @@ WebAssembly tests are built using [Proxy-Wasm C++ SDK] and [Proxy-Wasm Rust SDK], as such, they bring their own set of dependencies. +## Cargo dependencies. + +In order to update Cargo dependencies, please make sure that Rust and Cargo +are installed, and run this tool: + +``` +bash tools/update_crates.sh +``` + +which will regenerate Bazel rules in `bazel/external/cargo/`. + + [Proxy-Wasm C++ SDK]: https://github.com/proxy-wasm/proxy-wasm-cpp-sdk [Proxy-Wasm Rust SDK]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk diff --git a/bazel/external/cargo/BUILD.bazel b/bazel/external/cargo/BUILD.bazel new file mode 100644 index 0000000000000..1c2ac630f0eca --- /dev/null +++ b/bazel/external/cargo/BUILD.bazel @@ -0,0 +1,30 @@ +""" +@generated +cargo-raze generated Bazel file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +package(default_visibility = ["//visibility:public"]) + +licenses([ + "notice", # See individual crates for specific licenses +]) + +# Aliased targets +alias( + name = "protobuf", + actual = "@raze__protobuf__2_24_1//:protobuf", + tags = [ + "cargo-raze", + "manual", + ], +) + +# Export file for Stardoc support +exports_files( + [ + "crates.bzl", + ], + visibility = ["//visibility:public"], +) diff --git a/bazel/external/cargo/Cargo.raze.lock b/bazel/external/cargo/Cargo.raze.lock new file mode 100644 index 0000000000000..c4c4b979f7cae --- /dev/null +++ b/bazel/external/cargo/Cargo.raze.lock @@ -0,0 +1,14 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "protobuf" +version = "2.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db50e77ae196458ccd3dc58a31ea1a90b0698ab1b7928d89f644c25d72070267" + +[[package]] +name = "proxy-wasm-envoy-tests" +version = "0.0.1" +dependencies = [ + "protobuf", +] diff --git a/bazel/external/cargo/Cargo.toml b/bazel/external/cargo/Cargo.toml new file mode 100644 index 0000000000000..1063b0a68b6c6 --- /dev/null +++ b/bazel/external/cargo/Cargo.toml @@ -0,0 +1,29 @@ +[package] +description = "Proxy-Wasm tests for Envoy" +name = "proxy-wasm-envoy-tests" +version = "0.0.1" +authors = ["Piotr Sikora "] +edition = "2018" + +[dependencies] +protobuf = "2" + +[profile.release] +lto = true +opt-level = 3 +panic = "abort" + +[package.metadata.raze] +package_aliases_dir = "." +workspace_path = "//bazel/external/cargo" +genmode = "Remote" + +[[example]] +name = "grpc_call_rust" +path = "../../../test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs" +crate-type = ["cdylib"] + +[[example]] +name = "grpc_stream_rust" +path = "../../../test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs" +crate-type = ["cdylib"] diff --git a/bazel/external/cargo/crates.bzl b/bazel/external/cargo/crates.bzl new file mode 100644 index 0000000000000..9bcf1409887cd --- /dev/null +++ b/bazel/external/cargo/crates.bzl @@ -0,0 +1,22 @@ +""" +@generated +cargo-raze generated Bazel file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") # buildifier: disable=load +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # buildifier: disable=load +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") # buildifier: disable=load + +def raze_fetch_remote_crates(): + """This function defines a collection of repos and should be called in a WORKSPACE file""" + maybe( + http_archive, + name = "raze__protobuf__2_24_1", + url = "https://crates.io/api/v1/crates/protobuf/2.24.1/download", + type = "tar.gz", + sha256 = "db50e77ae196458ccd3dc58a31ea1a90b0698ab1b7928d89f644c25d72070267", + strip_prefix = "protobuf-2.24.1", + build_file = Label("//bazel/external/cargo/remote:BUILD.protobuf-2.24.1.bazel"), + ) diff --git a/bazel/external/cargo/remote/BUILD.bazel b/bazel/external/cargo/remote/BUILD.bazel new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/bazel/external/cargo/remote/BUILD.protobuf-2.24.1.bazel b/bazel/external/cargo/remote/BUILD.protobuf-2.24.1.bazel new file mode 100644 index 0000000000000..30c044876e4ca --- /dev/null +++ b/bazel/external/cargo/remote/BUILD.protobuf-2.24.1.bazel @@ -0,0 +1,87 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//bazel/external/cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT" +]) + +# Generated Targets +# buildifier: disable=out-of-order-load +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +cargo_build_script( + name = "protobuf_build_script", + srcs = glob(["**/*.rs"]), + build_script_env = { + }, + crate_features = [ + ], + crate_root = "build.rs", + data = glob(["**"]), + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "2.24.1", + visibility = ["//visibility:private"], + deps = [ + ], +) + +# Unsupported target "coded_input_stream" with type "bench" omitted + +# Unsupported target "coded_output_stream" with type "bench" omitted + +rust_library( + name = "protobuf", + srcs = glob(["**/*.rs"]), + crate_features = [ + ], + crate_root = "src/lib.rs", + crate_type = "lib", + data = [], + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "2.24.1", + # buildifier: leave-alone + deps = [ + ":protobuf_build_script", + ], +) diff --git a/bazel/repositories_extra.bzl b/bazel/repositories_extra.bzl index c86461e1a1893..34a4c59d50f36 100644 --- a/bazel/repositories_extra.bzl +++ b/bazel/repositories_extra.bzl @@ -1,6 +1,7 @@ load("@rules_python//python:repositories.bzl", "py_repositories") load("@rules_python//python:pip.bzl", "pip_install") load("@proxy_wasm_cpp_host//bazel/cargo:crates.bzl", "proxy_wasm_cpp_host_fetch_remote_crates") +load("//bazel/external/cargo:crates.bzl", "raze_fetch_remote_crates") # Python dependencies. def _python_deps(): @@ -131,3 +132,4 @@ def _python_deps(): def envoy_dependencies_extra(): _python_deps() proxy_wasm_cpp_host_fetch_remote_crates() + raze_fetch_remote_crates() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index e3db3a56e7a80..8b6bc50455f40 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -999,12 +999,12 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (Rust SDK)", project_desc = "WebAssembly for Proxies (Rust SDK)", project_url = "https://github.com/proxy-wasm/proxy-wasm-rust-sdk", - version = "28a94df25659b2107b67a11df0112f8f6833558b", - sha256 = "d3da0042fc119282223b7955962e8b3eed261242c8493f9dc8d07a08ca7e2e3e", + version = "4f79a79400713cd68d5df4943476f6fe4507bbd2", + sha256 = "7a6793ef05f108ea9cf55ab00e4e3cdc37cbc961aecb7a956a301820874c64e2", strip_prefix = "proxy-wasm-rust-sdk-{version}", urls = ["https://github.com/proxy-wasm/proxy-wasm-rust-sdk/archive/{version}.tar.gz"], use_category = ["test_only"], - release_date = "2021-02-09", + release_date = "2021-07-01", cpe = "N/A", ), emscripten_toolchain = dict( @@ -1022,13 +1022,13 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "Bazel rust rules", project_desc = "Bazel rust rules (used by Wasm)", project_url = "https://github.com/bazelbuild/rules_rust", - version = "1b648302edb64d3ddcc159655bf065bff40e6571", - sha256 = "242deacf4c9e4274d90964689dfae6c245bfb1bfa5e3336b2ad3b44f2541b70c", + version = "7e7246f6c48a5d4e69744cd79b9ccb8886966ee2", + sha256 = "d54b379559f3fe6ff0cd251be216a5e35acf241451eec8144455482e8f4748f8", strip_prefix = "rules_rust-{version}", urls = ["https://github.com/bazelbuild/rules_rust/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], extensions = ["envoy.wasm.runtime.wasmtime"], - release_date = "2021-04-02", + release_date = "2021-06-29", cpe = "N/A", ), rules_antlr = dict( diff --git a/test/extensions/filters/http/wasm/BUILD b/test/extensions/filters/http/wasm/BUILD index 0a3b7363af8a2..fdda95d42d7d9 100644 --- a/test/extensions/filters/http/wasm/BUILD +++ b/test/extensions/filters/http/wasm/BUILD @@ -25,6 +25,8 @@ envoy_extension_cc_test( ]) + envoy_select_wasm_rust_tests([ "//test/extensions/filters/http/wasm/test_data:async_call_rust.wasm", "//test/extensions/filters/http/wasm/test_data:body_rust.wasm", + "//test/extensions/filters/http/wasm/test_data:grpc_call_rust.wasm", + "//test/extensions/filters/http/wasm/test_data:grpc_stream_rust.wasm", "//test/extensions/filters/http/wasm/test_data:headers_rust.wasm", "//test/extensions/filters/http/wasm/test_data:metadata_rust.wasm", "//test/extensions/filters/http/wasm/test_data:panic_rust.wasm", diff --git a/test/extensions/filters/http/wasm/test_data/BUILD b/test/extensions/filters/http/wasm/test_data/BUILD index abee6c6247985..90a1238faf276 100644 --- a/test/extensions/filters/http/wasm/test_data/BUILD +++ b/test/extensions/filters/http/wasm/test_data/BUILD @@ -29,6 +29,26 @@ wasm_rust_binary( ], ) +wasm_rust_binary( + name = "grpc_call_rust.wasm", + srcs = ["grpc_call_rust.rs"], + deps = [ + "@proxy_wasm_rust_sdk//:proxy_wasm", + "@proxy_wasm_rust_sdk//bazel/cargo:log", + "//bazel/external/cargo:protobuf", + ], +) + +wasm_rust_binary( + name = "grpc_stream_rust.wasm", + srcs = ["grpc_stream_rust.rs"], + deps = [ + "@proxy_wasm_rust_sdk//:proxy_wasm", + "@proxy_wasm_rust_sdk//bazel/cargo:log", + "//bazel/external/cargo:protobuf", + ], +) + wasm_rust_binary( name = "headers_rust.wasm", srcs = ["headers_rust.rs"], diff --git a/test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs b/test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs new file mode 100644 index 0000000000000..40cb523cbd8d8 --- /dev/null +++ b/test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs @@ -0,0 +1,84 @@ +use log::{debug, error}; +use protobuf::well_known_types::Value; +use protobuf::Message; +use proxy_wasm::traits::{Context, HttpContext, RootContext}; +use proxy_wasm::types::*; +use std::cell::Cell; +use std::time::Duration; + +thread_local! { + // TODO(PiotrSikora): use child-to-parent reference once improved in the SDK. + static CALLOUT_ID: Cell> = Cell::new(None); +} + +#[no_mangle] +pub fn _start() { + proxy_wasm::set_log_level(LogLevel::Trace); + proxy_wasm::set_root_context(|_| -> Box { Box::new(TestGrpcCallRoot) }); + proxy_wasm::set_http_context(|_, _| -> Box { Box::new(TestGrpcCall) }); +} + +struct TestGrpcCallRoot; + +impl RootContext for TestGrpcCallRoot { + fn on_queue_ready(&mut self, _: u32) { + CALLOUT_ID.with(|saved_id| { + if let Some(callout_id) = saved_id.get() { + self.cancel_grpc_call(callout_id); + } + }); + } +} + +impl Context for TestGrpcCallRoot {} + +struct TestGrpcCall; + +impl HttpContext for TestGrpcCall { + fn on_http_request_headers(&mut self, _: usize) -> Action { + let mut value = Value::new(); + value.set_string_value(String::from("request")); + let message = value.write_to_bytes().unwrap(); + + match self.dispatch_grpc_call( + "bogus grpc_service", + "service", + "method", + vec![("source", b"grpc_call")], + Some(&message), + Duration::from_secs(1), + ) { + Ok(_) => error!("bogus grpc_service succeeded"), + Err(_) => error!("bogus grpc_service rejected"), + }; + + match self.dispatch_grpc_call( + "cluster", + "service", + "method", + vec![("source", b"grpc_call")], + Some(&message), + Duration::from_secs(1), + ) { + Ok(callout_id) => { + CALLOUT_ID.with(|saved_id| saved_id.set(Some(callout_id))); + error!("cluster call succeeded") + } + Err(_) => error!("cluster call rejected"), + }; + + Action::Pause + } +} + +impl Context for TestGrpcCall { + fn on_grpc_call_response(&mut self, _: u32, status_code: u32, response_size: usize) { + if status_code != 0 { + let (_, message) = self.get_grpc_status(); + debug!("failure {}", &message.as_deref().unwrap_or("")); + } else if let Some(response_bytes) = self.get_grpc_call_response_body(0, response_size) { + let value = Value::parse_from_bytes(&response_bytes).unwrap(); + debug!("{}", value.get_string_value()); + } + } +} diff --git a/test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs b/test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs new file mode 100644 index 0000000000000..bcb9d7b0df634 --- /dev/null +++ b/test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs @@ -0,0 +1,88 @@ +use log::{debug, error}; +use protobuf::well_known_types::Value; +use protobuf::Message; +use proxy_wasm::traits::{Context, HttpContext}; +use proxy_wasm::types::*; + +#[no_mangle] +pub fn _start() { + proxy_wasm::set_log_level(LogLevel::Trace); + proxy_wasm::set_http_context(|_, _| -> Box { Box::new(TestGrpcStream) }); +} + +struct TestGrpcStream; + +impl HttpContext for TestGrpcStream { + fn on_http_request_headers(&mut self, _: usize) -> Action { + match self.open_grpc_stream( + "bogus service string", + "service", + "method", + vec![("source", b"grpc_stream")], + ) { + Err(Status::ParseFailure) => error!("expected bogus service parse failure"), + Ok(_) => error!("unexpected bogus service string OK"), + Err(_) => error!("unexpected bogus service string error"), + }; + + match self.open_grpc_stream( + "cluster", + "service", + "bad method", + vec![("source", b"grpc_stream")], + ) { + Err(Status::InternalFailure) => error!("expected bogus method call failure"), + Ok(_) => error!("unexpected bogus method call OK"), + Err(_) => error!("unexpected bogus method call error"), + }; + + match self.open_grpc_stream( + "cluster", + "service", + "method", + vec![("source", b"grpc_stream")], + ) { + Ok(_) => error!("cluster call succeeded"), + Err(_) => error!("cluster call rejected"), + }; + + Action::Pause + } +} + +impl Context for TestGrpcStream { + fn on_grpc_stream_initial_metadata(&mut self, callout_id: u32, _: u32) { + if self.get_grpc_stream_initial_metadata_value("test") == Some(b"reset".to_vec()) { + self.cancel_grpc_stream(callout_id); + } + } + + fn on_grpc_stream_message(&mut self, callout_id: u32, message_size: usize) { + if let Some(message_bytes) = self.get_grpc_call_response_body(0, message_size) { + let response = Value::parse_from_bytes(&message_bytes).unwrap(); + let string = response.get_string_value(); + if string == String::from("close") { + self.close_grpc_stream(callout_id); + } else { + let value = Value::new(); + let message = value.write_to_bytes().unwrap(); + self.send_grpc_stream_message(callout_id, Some(&message), false); + } + debug!("response {}", string); + } + } + + fn on_grpc_stream_trailing_metadata(&mut self, _: u32, _: u32) { + let _ = self.get_grpc_stream_trailing_metadata_value("foo"); + } + + fn on_grpc_stream_close(&mut self, callout_id: u32, _: u32) { + let (_, message) = self.get_grpc_status(); + debug!("close {}", &message.as_deref().unwrap_or("")); + match message.as_deref() { + Some("close") => self.close_grpc_stream(callout_id), + Some("ok") => (), + _ => self.cancel_grpc_stream(callout_id), + }; + } +} diff --git a/test/extensions/filters/http/wasm/wasm_filter_test.cc b/test/extensions/filters/http/wasm/wasm_filter_test.cc index 737b1aa381c3e..b32fe29f67df0 100644 --- a/test/extensions/filters/http/wasm/wasm_filter_test.cc +++ b/test/extensions/filters/http/wasm/wasm_filter_test.cc @@ -815,7 +815,7 @@ TEST_P(WasmHttpFilterTest, AsyncCallFailure) { callbacks->onFailure(request, Http::AsyncClient::FailureReason::Reset); return proxy_wasm::WasmResult::Ok; })); - // TODO(PiotrSikora): RootContext handling is incomplete in the Rust SDK. + // TODO(PiotrSikora): Switching back to the original context is inconsistent between SDKs. if (std::get<1>(GetParam()) == "rust") { EXPECT_CALL(filter(), log_(spdlog::level::info, Eq("async_call failed"))); } else { @@ -874,12 +874,16 @@ TEST_P(WasmHttpFilterTest, AsyncCallAfterDestroyed) { } TEST_P(WasmHttpFilterTest, GrpcCall) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. + if (std::get<0>(GetParam()) == "wamr" && std::get<1>(GetParam()) == "rust") { + // WAMR hardcodes 16 KiB stack, which is too small to decode protobufs in Rust. return; } - - std::array proto_or_cluster{"grpc_call_proto", "grpc_call"}; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_call"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_call_proto"); + } for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; setupTest(id); @@ -931,7 +935,12 @@ TEST_P(WasmHttpFilterTest, GrpcCall) { Invoke([&](const GrpcService&, Stats::Scope&, bool) -> Grpc::AsyncClientFactoryPtr { return std::move(client_factory); })); - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response"))); + // TODO(PiotrSikora): Switching back to the original context is inconsistent between SDKs. + if (std::get<1>(GetParam()) == "rust") { + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("response"))); + } else { + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response"))); + } Http::TestRequestHeaderMapImpl request_headers{{":path", "/"}}; EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, false)); @@ -955,11 +964,16 @@ TEST_P(WasmHttpFilterTest, GrpcCall) { TEST_P(WasmHttpFilterTest, GrpcCallBadCall) { if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. + // TODO(PiotrSikora): not yet supported in the Rust SDK (pending update to ABI 0.2.1). return; } - std::array proto_or_cluster{"grpc_call_proto", "grpc_call"}; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_call"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_call_proto"); + } for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; setupTest(id); @@ -1003,12 +1017,12 @@ TEST_P(WasmHttpFilterTest, GrpcCallBadCall) { } TEST_P(WasmHttpFilterTest, GrpcCallFailure) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. - return; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_call"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_call_proto"); } - - std::array proto_or_cluster{"grpc_call_proto", "grpc_call"}; for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; setupTest(id); @@ -1060,7 +1074,12 @@ TEST_P(WasmHttpFilterTest, GrpcCallFailure) { Invoke([&](const GrpcService&, Stats::Scope&, bool) -> Grpc::AsyncClientFactoryPtr { return std::move(client_factory); })); - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("failure bad"))); + // TODO(PiotrSikora): Switching back to the original context is inconsistent between SDKs. + if (std::get<1>(GetParam()) == "rust") { + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("failure bad"))); + } else { + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("failure bad"))); + } Http::TestRequestHeaderMapImpl request_headers{{":path", "/"}}; EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, false)); @@ -1087,12 +1106,12 @@ TEST_P(WasmHttpFilterTest, GrpcCallFailure) { } TEST_P(WasmHttpFilterTest, GrpcCallCancel) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. - return; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_call"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_call_proto"); } - - std::array proto_or_cluster{"grpc_call_proto", "grpc_call"}; for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; setupTest(id); @@ -1153,12 +1172,12 @@ TEST_P(WasmHttpFilterTest, GrpcCallCancel) { } TEST_P(WasmHttpFilterTest, GrpcCallClose) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. - return; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_call"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_call_proto"); } - - std::array proto_or_cluster{"grpc_call_proto", "grpc_call"}; for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; setupTest(id); @@ -1219,11 +1238,12 @@ TEST_P(WasmHttpFilterTest, GrpcCallClose) { } TEST_P(WasmHttpFilterTest, GrpcCallAfterDestroyed) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. - return; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_call"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_call_proto"); } - std::array proto_or_cluster{"grpc_call_proto", "grpc_call"}; for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; setupTest(id); @@ -1334,11 +1354,16 @@ void WasmHttpFilterTest::setupGrpcStreamTest(Grpc::RawAsyncStreamCallbacks*& cal } TEST_P(WasmHttpFilterTest, GrpcStream) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. + if (std::get<0>(GetParam()) == "wamr" && std::get<1>(GetParam()) == "rust") { + // WAMR hardcodes 16 KiB stack, which is too small to decode protobufs in Rust. return; } - std::array proto_or_cluster{"grpc_stream_proto", "grpc_stream"}; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_stream"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_stream_proto"); + } for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; Grpc::RawAsyncStreamCallbacks* callbacks = nullptr; @@ -1357,8 +1382,15 @@ TEST_P(WasmHttpFilterTest, GrpcStream) { log_(spdlog::level::err, Eq(absl::string_view("cluster call succeeded")))); } - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response response"))); - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("close done"))); + // TODO(PiotrSikora): Switching back to the original context is inconsistent between SDKs. + if (std::get<1>(GetParam()) == "rust") { + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("response response"))); + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("close done"))); + } else { + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response response"))); + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("close done"))); + } + Http::TestRequestHeaderMapImpl request_headers{{":path", "/"}}; EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, false)); @@ -1384,11 +1416,16 @@ TEST_P(WasmHttpFilterTest, GrpcStream) { // Local close followed by remote close. TEST_P(WasmHttpFilterTest, GrpcStreamCloseLocal) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. + if (std::get<0>(GetParam()) == "wamr" && std::get<1>(GetParam()) == "rust") { + // WAMR hardcodes 16 KiB stack, which is too small to decode protobufs in Rust. return; } - std::array proto_or_cluster{"grpc_stream_proto", "grpc_stream"}; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_stream"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_stream_proto"); + } for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; Grpc::RawAsyncStreamCallbacks* callbacks = nullptr; @@ -1407,8 +1444,15 @@ TEST_P(WasmHttpFilterTest, GrpcStreamCloseLocal) { log_(spdlog::level::err, Eq(absl::string_view("cluster call succeeded")))); } - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response close"))); - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("close ok"))); + // TODO(PiotrSikora): Switching back to the original context is inconsistent between SDKs. + if (std::get<1>(GetParam()) == "rust") { + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("response close"))); + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("close ok"))); + } else { + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response close"))); + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("close ok"))); + } + Http::TestRequestHeaderMapImpl request_headers{{":path", "/"}}; EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, false)); @@ -1433,12 +1477,16 @@ TEST_P(WasmHttpFilterTest, GrpcStreamCloseLocal) { // Remote close followed by local close. TEST_P(WasmHttpFilterTest, GrpcStreamCloseRemote) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. + if (std::get<0>(GetParam()) == "wamr" && std::get<1>(GetParam()) == "rust") { + // WAMR hardcodes 16 KiB stack, which is too small to decode protobufs in Rust. return; } - - std::array proto_or_cluster{"grpc_stream_proto", "grpc_stream"}; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_stream"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_stream_proto"); + } for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; Grpc::RawAsyncStreamCallbacks* callbacks = nullptr; @@ -1457,8 +1505,15 @@ TEST_P(WasmHttpFilterTest, GrpcStreamCloseRemote) { log_(spdlog::level::err, Eq(absl::string_view("cluster call succeeded")))); } - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response response"))); - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("close close"))); + // TODO(PiotrSikora): Switching back to the original context is inconsistent between SDKs. + if (std::get<1>(GetParam()) == "rust") { + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("response response"))); + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("close close"))); + } else { + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response response"))); + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("close close"))); + } + Http::TestRequestHeaderMapImpl request_headers{{":path", "/"}}; EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, false)); @@ -1482,12 +1537,12 @@ TEST_P(WasmHttpFilterTest, GrpcStreamCloseRemote) { } TEST_P(WasmHttpFilterTest, GrpcStreamCancel) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. - return; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_stream"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_stream_proto"); } - - std::array proto_or_cluster{"grpc_stream_proto", "grpc_stream"}; for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; Grpc::RawAsyncStreamCallbacks* callbacks = nullptr; @@ -1529,12 +1584,16 @@ TEST_P(WasmHttpFilterTest, GrpcStreamCancel) { } TEST_P(WasmHttpFilterTest, GrpcStreamOpenAtShutdown) { - if (std::get<1>(GetParam()) == "rust") { - // TODO(PiotrSikora): gRPC call outs not yet supported in the Rust SDK. + if (std::get<0>(GetParam()) == "wamr" && std::get<1>(GetParam()) == "rust") { + // WAMR hardcodes 16 KiB stack, which is too small to decode protobufs in Rust. return; } - - std::array proto_or_cluster{"grpc_stream_proto", "grpc_stream"}; + std::vector proto_or_cluster; + proto_or_cluster.push_back("grpc_stream"); + if (std::get<1>(GetParam()) == "cpp") { + // cluster definition passed as a protobuf is only supported in C++ SDK. + proto_or_cluster.push_back("grpc_stream_proto"); + } for (const auto& id : proto_or_cluster) { TestScopedRuntime scoped_runtime; Grpc::RawAsyncStreamCallbacks* callbacks = nullptr; @@ -1553,7 +1612,13 @@ TEST_P(WasmHttpFilterTest, GrpcStreamOpenAtShutdown) { log_(spdlog::level::err, Eq(absl::string_view("cluster call succeeded")))); } - EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response response"))); + // TODO(PiotrSikora): Switching back to the original context is inconsistent between SDKs. + if (std::get<1>(GetParam()) == "rust") { + EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq("response response"))); + } else { + EXPECT_CALL(rootContext(), log_(spdlog::level::debug, Eq("response response"))); + } + Http::TestRequestHeaderMapImpl request_headers{{":path", "/"}}; EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, false)); diff --git a/tools/check_repositories.sh b/tools/check_repositories.sh index ef3b77e194b35..8930821652ca7 100755 --- a/tools/check_repositories.sh +++ b/tools/check_repositories.sh @@ -12,8 +12,8 @@ fi # Check whether number of defined `url =` or `urls =` and `sha256 =` kwargs in # repository definitions is equal. -urls_count=$(git grep -E "\