Summary: `/*` is the standard throughout open source code. For example, Firefox uses single /*: https://hg.mozilla.org/mozilla-central/file/21d22b2f541258d3d1cf96c7ba5ad73e96e616b5/gfx/ipc/CompositorWidgetVsyncObserver.cpp#l3 In addition, Rust considers `/**` to be a doc comment (similar to Javadoc) and having such a comment at the beginning of the file causes `rustc` to barf. Note that some JavaScript tooling requires `/**`. This is OK since JavaScript files were not covered by the linter in the first place, but it would be good to have that tooling fixed too. Reviewed By: zertosh Differential Revision: D15640366 fbshipit-source-id: b4ed4599071516364d6109720750d6a43304c089
99 lines
2.6 KiB
C++
99 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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 <folly/Singleton.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 flipperEventBase = new EventBase();
|
|
auto connectionEventBase = new EventBase();
|
|
auto flipperThread = std::thread([flipperEventBase](){
|
|
flipperEventBase->loopForever();
|
|
});
|
|
auto connectionThread = std::thread([connectionEventBase](){
|
|
connectionEventBase->loopForever();
|
|
});
|
|
auto config = FlipperInitConfig {
|
|
DeviceData {},
|
|
flipperEventBase,
|
|
connectionEventBase
|
|
};
|
|
auto instance = std::make_shared<FlipperConnectionManagerImpl>(config, state, contextStore);
|
|
|
|
instance->start();
|
|
|
|
flipperEventBase->terminateLoopSoon();
|
|
connectionEventBase->terminateLoopSoon();
|
|
|
|
flipperThread.join();
|
|
connectionThread.join();
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace flipper
|
|
} // namespace facebook
|