From 8ea9c7df226de0f56073f2c8404bf0ae3527bb8f Mon Sep 17 00:00:00 2001 From: John Plevyak Date: Thu, 20 Aug 2020 14:50:43 -0700 Subject: [PATCH 1/2] Fix nack on background cache fill. Signed-off-by: John Plevyak --- source/extensions/common/wasm/wasm.cc | 1 + .../filters/http/wasm/config_test.cc | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/extensions/common/wasm/wasm.cc b/source/extensions/common/wasm/wasm.cc index 46f40b69f3f28..837f770478e99 100644 --- a/source/extensions/common/wasm/wasm.cc +++ b/source/extensions/common/wasm/wasm.cc @@ -412,6 +412,7 @@ static bool createWasmInternal(const VmConfig& vm_config, const PluginSharedPtr& ENVOY_LOG_TO_LOGGER(Envoy::Logger::Registry::getLog(Envoy::Logger::Id::wasm), trace, fmt::format("Failed to load Wasm code (fetching) from {}", source)); cb(nullptr); + return false; } else { remote_data_provider = std::make_unique( cluster_manager, init_manager, vm_config.code().remote(), dispatcher, random, true, diff --git a/test/extensions/filters/http/wasm/config_test.cc b/test/extensions/filters/http/wasm/config_test.cc index 67224a55cecad..46a57ba409b63 100644 --- a/test/extensions/filters/http/wasm/config_test.cc +++ b/test/extensions/filters/http/wasm/config_test.cc @@ -22,6 +22,9 @@ using testing::ReturnRef; namespace Envoy { namespace Extensions { + +using Common::Wasm::WasmException; + namespace HttpFilters { namespace Wasm { @@ -162,8 +165,7 @@ TEST_P(WasmFilterConfigTest, YamlLoadInlineBadCode) { TestUtility::loadFromYaml(yaml, proto_config); WasmFilterConfig factory; EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config, "stats", context_), - Extensions::Common::Wasm::WasmException, - "Unable to create Wasm HTTP filter "); + WasmException, "Unable to create Wasm HTTP filter "); } TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasm) { @@ -253,7 +255,8 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasmFailOnUncachedThenSucceed) { return &request; })); - factory.createFilterFactoryFromProto(proto_config, "stats", context_); + EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config, "stats", context_), + WasmException, "Unable to create Wasm HTTP filter "); EXPECT_CALL(init_watcher_, ready()); context_.initManager().initialize(init_watcher_); @@ -264,7 +267,7 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasmFailOnUncachedThenSucceed) { EXPECT_CALL(context_, initManager()).WillRepeatedly(ReturnRef(init_manager2)); - Http::FilterFactoryCb cb = factory.createFilterFactoryFromProto(proto_config, "stats", context_); + auto cb = factory.createFilterFactoryFromProto(proto_config, "stats", context_); EXPECT_CALL(init_watcher2, ready()); init_manager2.initialize(init_watcher2); @@ -320,7 +323,8 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasmFailCachedThenSucceed) { })); // Case 1: fail and fetch in the background, got 503, cache failure. - factory.createFilterFactoryFromProto(proto_config, "stats", context_); + EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config, "stats", context_), + WasmException, "Unable to create Wasm HTTP filter "); EXPECT_CALL(init_watcher_, ready()); context_.initManager().initialize(init_watcher_); @@ -331,7 +335,8 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasmFailCachedThenSucceed) { Init::ExpectableWatcherImpl init_watcher2; EXPECT_CALL(context_, initManager()).WillRepeatedly(ReturnRef(init_manager2)); - factory.createFilterFactoryFromProto(proto_config, "stats", context_); + EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config, "stats", context_), + WasmException, "Unable to create Wasm HTTP filter "); EXPECT_CALL(init_watcher2, ready()); init_manager2.initialize(init_watcher2); @@ -358,7 +363,8 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasmFailCachedThenSucceed) { EXPECT_CALL(context_, initManager()).WillRepeatedly(ReturnRef(init_manager3)); - factory.createFilterFactoryFromProto(proto_config, "stats", context_); + EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config, "stats", context_), + WasmException, "Unable to create Wasm HTTP filter "); EXPECT_CALL(init_watcher3, ready()); init_manager3.initialize(init_watcher3); From dddd11460c4eb5daa7306015f049ecf688776ea6 Mon Sep 17 00:00:00 2001 From: John Plevyak Date: Tue, 25 Aug 2020 13:30:55 -0700 Subject: [PATCH 2/2] Fixup test. Signed-off-by: John Plevyak --- test/extensions/filters/http/wasm/config_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/extensions/filters/http/wasm/config_test.cc b/test/extensions/filters/http/wasm/config_test.cc index 46a57ba409b63..7d9b5142ddd65 100644 --- a/test/extensions/filters/http/wasm/config_test.cc +++ b/test/extensions/filters/http/wasm/config_test.cc @@ -418,7 +418,8 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasmFailCachedThenSucceed) { EXPECT_CALL(context_, initManager()).WillRepeatedly(ReturnRef(init_manager5)); - factory.createFilterFactoryFromProto(proto_config2, "stats", context_); + EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config2, "stats", context_), + WasmException, "Unable to create Wasm HTTP filter "); EXPECT_CALL(init_watcher_, ready()); context_.initManager().initialize(init_watcher_);