Updated TestAllocatorProcess to avoid the test warnings. Review: https://reviews.apache.org/r/29990
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b7bb6696 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b7bb6696 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b7bb6696 Branch: refs/heads/master Commit: b7bb6696b5a78dbc896b4756b7d4123e86c01635 Parents: ccd697d Author: Benjamin Mahler <[email protected]> Authored: Fri Jan 16 14:10:05 2015 -0800 Committer: Benjamin Mahler <[email protected]> Committed: Wed Jan 28 15:40:47 2015 -0800 ---------------------------------------------------------------------- src/tests/containerizer.cpp | 9 +++++--- src/tests/mesos.hpp | 48 ++++++++++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/b7bb6696/src/tests/containerizer.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer.cpp b/src/tests/containerizer.cpp index a17e1e0..26b87ac 100644 --- a/src/tests/containerizer.cpp +++ b/src/tests/containerizer.cpp @@ -222,9 +222,12 @@ void TestContainerizer::setup() // warning "Uninteresting mock function call" unless each tests puts // the expectations in place which would make the tests much more // verbose. - // See groups.google.com/forum/#!topic/googlemock/EX4kLxddlko for a - // suggestion for how we might be able to use 'NiceMock' here - // instead. + // + // TODO(bmahler): Update this to use the same style as the + // TestAllocatorProcess, which allows us to have default actions + // 'DoDefault', without requiring each test to put expectations in + // place. + EXPECT_CALL(*this, recover(_)) .WillRepeatedly(Return(Nothing())); http://git-wip-us.apache.org/repos/asf/mesos/blob/b7bb6696/src/tests/mesos.hpp ---------------------------------------------------------------------- diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp index 6bb5a7f..17c2d8f 100644 --- a/src/tests/mesos.hpp +++ b/src/tests/mesos.hpp @@ -62,6 +62,11 @@ #include "tests/zookeeper.hpp" #endif // MESOS_HAS_JAVA +using ::testing::_; +using ::testing::An; +using ::testing::DoDefault; +using ::testing::Return; + namespace mesos { namespace internal { namespace tests { @@ -552,9 +557,6 @@ class MockGarbageCollector : public slave::GarbageCollector public: MockGarbageCollector() { - using ::testing::_; - using ::testing::Return; - // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()' // for more details. @@ -649,9 +651,6 @@ class MockAuthorizer : public Authorizer public: MockAuthorizer() { - using ::testing::An; - using ::testing::Return; - // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()' // for more details. @@ -683,49 +682,84 @@ public: // Spawn the underlying allocator process. process::spawn(real); - using ::testing::_; + // We use 'ON_CALL' and 'WillByDefault' here to specify the + // default actions (call in to the real allocator). This allows + // the tests to leverage the 'DoDefault' action. + // However, 'ON_CALL' results in a "Uninteresting mock function + // call" warning unless each test puts expectations in place. + // As a result, we also use 'EXPECT_CALL' and 'WillRepeatedly' + // to get the best of both worlds: the ability to use 'DoDefault' + // and no warnings when expectations are not explicit. ON_CALL(*this, initialize(_, _, _)) .WillByDefault(InvokeInitialize(this)); + EXPECT_CALL(*this, initialize(_, _, _)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, addFramework(_, _, _)) .WillByDefault(InvokeFrameworkAdded(this)); + EXPECT_CALL(*this, addFramework(_, _, _)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, removeFramework(_)) .WillByDefault(InvokeFrameworkRemoved(this)); + EXPECT_CALL(*this, removeFramework(_)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, activateFramework(_)) .WillByDefault(InvokeFrameworkActivated(this)); + EXPECT_CALL(*this, activateFramework(_)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, deactivateFramework(_)) .WillByDefault(InvokeFrameworkDeactivated(this)); + EXPECT_CALL(*this, deactivateFramework(_)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, addSlave(_, _, _, _)) .WillByDefault(InvokeSlaveAdded(this)); + EXPECT_CALL(*this, addSlave(_, _, _, _)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, removeSlave(_)) .WillByDefault(InvokeSlaveRemoved(this)); + EXPECT_CALL(*this, removeSlave(_)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, activateSlave(_)) .WillByDefault(InvokeSlaveReactivated(this)); + EXPECT_CALL(*this, activateSlave(_)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, deactivateSlave(_)) .WillByDefault(InvokeSlaveDeactivated(this)); + EXPECT_CALL(*this, deactivateSlave(_)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, updateWhitelist(_)) .WillByDefault(InvokeUpdateWhitelist(this)); + EXPECT_CALL(*this, updateWhitelist(_)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, requestResources(_, _)) .WillByDefault(InvokeResourcesRequested(this)); + EXPECT_CALL(*this, requestResources(_, _)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, updateAllocation(_, _, _)) .WillByDefault(InvokeUpdateAllocation(this)); + EXPECT_CALL(*this, updateAllocation(_, _, _)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, recoverResources(_, _, _, _)) .WillByDefault(InvokeResourcesRecovered(this)); + EXPECT_CALL(*this, recoverResources(_, _, _, _)) + .WillRepeatedly(DoDefault()); ON_CALL(*this, reviveOffers(_)) .WillByDefault(InvokeOffersRevived(this)); + EXPECT_CALL(*this, reviveOffers(_)) + .WillRepeatedly(DoDefault()); } ~TestAllocatorProcess()
