diff --git a/test/common/config/BUILD b/test/common/config/BUILD index 7fec979a8a8f..6ad424aa8ce5 100644 --- a/test/common/config/BUILD +++ b/test/common/config/BUILD @@ -82,7 +82,6 @@ envoy_cc_test( envoy_cc_test( name = "filesystem_subscription_impl_test", srcs = ["filesystem_subscription_impl_test.cc"], - tags = ["fails_on_windows"], deps = [ ":filesystem_subscription_test_harness", "//test/mocks/event:event_mocks", @@ -101,6 +100,8 @@ envoy_cc_test_library( "//source/common/config:utility_lib", "//source/common/event:dispatcher_lib", "//test/mocks/config:config_mocks", + "//test/mocks/event:event_mocks", + "//test/mocks/filesystem:filesystem_mocks", "//test/mocks/protobuf:protobuf_mocks", "//test/test_common:environment_lib", "//test/test_common:test_time_lib", @@ -294,7 +295,6 @@ envoy_cc_test( envoy_cc_test( name = "subscription_impl_test", srcs = ["subscription_impl_test.cc"], - tags = ["fails_on_windows"], deps = [ ":delta_subscription_test_harness", ":filesystem_subscription_test_harness", diff --git a/test/common/config/filesystem_subscription_test_harness.h b/test/common/config/filesystem_subscription_test_harness.h index d8d721eb060a..2f52f2629497 100644 --- a/test/common/config/filesystem_subscription_test_harness.h +++ b/test/common/config/filesystem_subscription_test_harness.h @@ -13,6 +13,8 @@ #include "test/common/config/subscription_test_harness.h" #include "test/mocks/config/mocks.h" +#include "test/mocks/event/mocks.h" +#include "test/mocks/filesystem/mocks.h" #include "test/mocks/protobuf/mocks.h" #include "test/test_common/environment.h" #include "test/test_common/utility.h" @@ -21,6 +23,7 @@ #include "gtest/gtest.h" using testing::_; +using testing::InvokeWithoutArgs; using testing::NiceMock; namespace Envoy { @@ -30,13 +33,24 @@ class FilesystemSubscriptionTestHarness : public SubscriptionTestHarness { public: FilesystemSubscriptionTestHarness() : path_(TestEnvironment::temporaryPath("eds.json")), - api_(Api::createApiForTest(stats_store_, simTime())), - dispatcher_(api_->allocateDispatcher("test_thread")), + api_(Api::createApiForTest(stats_store_, simTime())), dispatcher_(setupDispatcher()), subscription_(*dispatcher_, path_, callbacks_, resource_decoder_, stats_, validation_visitor_, *api_) {} ~FilesystemSubscriptionTestHarness() override { TestEnvironment::removePath(path_); } + Event::DispatcherPtr setupDispatcher() { + auto dispatcher = std::make_unique(); + EXPECT_CALL(*dispatcher, createFilesystemWatcher_()).WillOnce(InvokeWithoutArgs([this] { + Filesystem::MockWatcher* mock_watcher = new Filesystem::MockWatcher(); + EXPECT_CALL(*mock_watcher, addWatch(path_, Filesystem::Watcher::Events::MovedTo, _)) + .WillOnce(Invoke([this](absl::string_view, uint32_t, + Filesystem::Watcher::OnChangedCb cb) { on_changed_cb_ = cb; })); + return mock_watcher; + })); + return dispatcher; + } + void startSubscription(const std::set& cluster_names) override { std::ifstream config_file(path_); file_at_start_ = config_file.good(); @@ -48,12 +62,11 @@ class FilesystemSubscriptionTestHarness : public SubscriptionTestHarness { } void updateFile(const std::string& json, bool run_dispatcher = true) { - // Write JSON contents to file, rename to path_ and run dispatcher to catch - // inotify. + // Write JSON contents to file, rename to path_ and invoke on change callback const std::string temp_path = TestEnvironment::writeStringToFileForTest("eds.json.tmp", json); TestEnvironment::renameFile(temp_path, path_); if (run_dispatcher) { - dispatcher_->run(Event::Dispatcher::RunType::NonBlock); + on_changed_cb_(Filesystem::Watcher::Events::MovedTo); } } @@ -118,6 +131,7 @@ class FilesystemSubscriptionTestHarness : public SubscriptionTestHarness { NiceMock validation_visitor_; Api::ApiPtr api_; Event::DispatcherPtr dispatcher_; + Filesystem::Watcher::OnChangedCb on_changed_cb_; NiceMock callbacks_; TestUtility::TestOpaqueResourceDecoderImpl resource_decoder_{"cluster_name"};