Skip to content
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

Windows: Fix filesystem subscription impl tests #12597

Merged
merged 4 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
24 changes: 19 additions & 5 deletions test/common/config/filesystem_subscription_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,6 +23,7 @@
#include "gtest/gtest.h"

using testing::_;
using testing::InvokeWithoutArgs;
using testing::NiceMock;

namespace Envoy {
Expand All @@ -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<Event::MockDispatcher>();
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<std::string>& cluster_names) override {
std::ifstream config_file(path_);
file_at_start_ = config_file.good();
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -118,6 +131,7 @@ class FilesystemSubscriptionTestHarness : public SubscriptionTestHarness {
NiceMock<ProtobufMessage::MockValidationVisitor> validation_visitor_;
Api::ApiPtr api_;
Event::DispatcherPtr dispatcher_;
Filesystem::Watcher::OnChangedCb on_changed_cb_;
NiceMock<Config::MockSubscriptionCallbacks> callbacks_;
TestUtility::TestOpaqueResourceDecoderImpl<envoy::config::endpoint::v3::ClusterLoadAssignment>
resource_decoder_{"cluster_name"};
Expand Down