Rename Sonar Tests
Summary: Part of sonar to flipper rename Reviewed By: passy Differential Revision: D9929101 fbshipit-source-id: f33e1ac7f88fbe88a9d48180d064b596603a3c58
This commit is contained in:
committed by
Facebook Github Bot
parent
3838decf1d
commit
c18c8ac802
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Flipper/FlipperConnectionManagerImpl.h>
|
||||
#include <FlipperTestLib/ConnectionContextStoreMock.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace flipper {
|
||||
namespace test {
|
||||
|
||||
using folly::EventBase;
|
||||
|
||||
class FlipperConnectionManagerImplTerminationTest : public ::testing::Test {
|
||||
protected:
|
||||
std::shared_ptr<FlipperState> state;
|
||||
std::shared_ptr<ConnectionContextStore> contextStore;
|
||||
void SetUp() override {
|
||||
// Folly singletons must be registered before they are used.
|
||||
// Without this, test fails in phabricator.
|
||||
folly::SingletonVault::singleton()->registrationComplete();
|
||||
state = std::make_shared<FlipperState>();
|
||||
contextStore = std::make_shared<ConnectionContextStoreMock>();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(FlipperConnectionManagerImplTerminationTest, testNullEventBaseGetsRejected) {
|
||||
try {
|
||||
auto instance = std::make_shared<FlipperConnectionManagerImpl>(FlipperInitConfig {
|
||||
DeviceData {},
|
||||
nullptr,
|
||||
new EventBase()
|
||||
},
|
||||
state,
|
||||
contextStore
|
||||
);
|
||||
FAIL();
|
||||
} catch (std::invalid_argument& e) {
|
||||
// Pass test
|
||||
}
|
||||
try {
|
||||
auto instance = std::make_shared<FlipperConnectionManagerImpl>(FlipperInitConfig {
|
||||
DeviceData {},
|
||||
new EventBase(),
|
||||
nullptr
|
||||
},
|
||||
state,
|
||||
contextStore
|
||||
);
|
||||
FAIL();
|
||||
} catch (std::invalid_argument& e) {
|
||||
// Pass test
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FlipperConnectionManagerImplTerminationTest, testNonStartedEventBaseDoesntHang) {
|
||||
auto config = FlipperInitConfig {
|
||||
DeviceData {},
|
||||
new EventBase(),
|
||||
new EventBase()
|
||||
};
|
||||
auto instance = std::make_shared<FlipperConnectionManagerImpl>(config, state, contextStore);
|
||||
instance->start();
|
||||
}
|
||||
|
||||
TEST_F(FlipperConnectionManagerImplTerminationTest, testStartedEventBaseDoesntHang) {
|
||||
auto sonarEventBase = new EventBase();
|
||||
auto connectionEventBase = new EventBase();
|
||||
auto sonarThread = std::thread([sonarEventBase](){
|
||||
sonarEventBase->loopForever();
|
||||
});
|
||||
auto connectionThread = std::thread([connectionEventBase](){
|
||||
connectionEventBase->loopForever();
|
||||
});
|
||||
auto config = FlipperInitConfig {
|
||||
DeviceData {},
|
||||
sonarEventBase,
|
||||
connectionEventBase
|
||||
};
|
||||
auto instance = std::make_shared<FlipperConnectionManagerImpl>(config, state, contextStore);
|
||||
|
||||
instance->start();
|
||||
|
||||
sonarEventBase->terminateLoopSoon();
|
||||
connectionEventBase->terminateLoopSoon();
|
||||
|
||||
sonarThread.join();
|
||||
connectionThread.join();
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace flipper
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user