Skip to content

Commit

Permalink
revert to count_ test
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Dai <silentdai@gmail.com>
  • Loading branch information
lambdai committed Nov 15, 2019
1 parent 9cddbda commit fb6569b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
15 changes: 4 additions & 11 deletions test/common/init/target_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,20 @@ TEST(InitTargetImplTest, ReadyWhenWatcherUnavailable) {
}

TEST(SharedTargetImplTest, InitializeTwiceBeforeReady) {
InSequence s;
ManagerImpl m1("m1");
ManagerImpl m2("m2");
ExpectableWatcherImpl w1;
ExpectableWatcherImpl w2;
ExpectableSharedTargetImpl t;
//t.expectInitialize();
m1.add(t);
// @mergeconflit: I want to verify Initalize invoked after m2.add(t).
// But if I swap the below lines the test is also passing.
//
// t.expectInitialize();
// m2.add(t);
EXPECT_EQ(0, t.count_);
m2.add(t);
t.expectInitialize();
//t.expectInitialize().Times();
EXPECT_EQ(0, t.count_);
EXPECT_EQ(Manager::State::Uninitialized, m1.state());
EXPECT_EQ(Manager::State::Uninitialized, m2.state());
m1.initialize(w1);
m2.initialize(w2);
EXPECT_EQ(1, t.count_);
EXPECT_EQ(Manager::State::Initializing, m1.state());
EXPECT_EQ(Manager::State::Initializing, m2.state());
w1.expectReady().Times(1);
Expand All @@ -91,7 +85,7 @@ TEST(SharedTargetImplTest, InitializeTwiceBeforeReady) {
EXPECT_EQ(Manager::State::Initialized, m1.state());
EXPECT_EQ(Manager::State::Initialized, m2.state());
}
/*

// Two managers initialize the same target at their own interests.
TEST(SharedTargetImplTest, ConcurrentManagerInitialization) {
ManagerImpl m1("m1");
Expand Down Expand Up @@ -187,7 +181,6 @@ TEST(SharedTargetImplTest, DetroyedSharedTargetIsConsideredReadyTarget) {
m.initialize(w);
EXPECT_EQ(Manager::State::Initialized, m.state());
}
*/
} // namespace
} // namespace Init
} // namespace Envoy
5 changes: 1 addition & 4 deletions test/mocks/init/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ ExpectableTargetImpl::expectInitializeWillCallReady() {
}

ExpectableSharedTargetImpl::ExpectableSharedTargetImpl(absl::string_view name)
: SharedTargetImpl(name, [this]() { initialize(); }) {}
: ExpectableSharedTargetImpl(name, [this]() { ++count_; }) {}
ExpectableSharedTargetImpl::ExpectableSharedTargetImpl(absl::string_view name, InitializeFn fn)
: SharedTargetImpl(name, fn) {}
::testing::internal::TypedExpectation<void()>& ExpectableSharedTargetImpl::expectInitialize() {
return EXPECT_CALL(*this, initialize());
}
} // namespace Init
} // namespace Envoy
7 changes: 1 addition & 6 deletions test/mocks/init/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,11 @@ class ExpectableTargetImpl : public TargetImpl {
::testing::internal::TypedExpectation<void()>& expectInitializeWillCallReady();
};

/**
* Borrow the idea from ExpectableTargetImpl. ExpectableSharedTargetImpl is a real SharedTargetImpl.
*/
class ExpectableSharedTargetImpl : public SharedTargetImpl {
public:
ExpectableSharedTargetImpl(absl::string_view name = "test");
ExpectableSharedTargetImpl(absl::string_view name, InitializeFn fn);
MOCK_METHOD0(initialize, void());

::testing::internal::TypedExpectation<void()>& expectInitialize();
int count_{0};
};

/**
Expand Down

0 comments on commit fb6569b

Please sign in to comment.