Skip to content
Permalink
Browse files
Fix assertion failure when using C++ ServiceTracker in the event loop.
  • Loading branch information
PengZheng committed Nov 16, 2021
1 parent bb9179a commit 64b7293a133695566c2563b9c058d515ec4384df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
@@ -550,6 +550,20 @@ TEST_F(CxxBundleContextTestSuite, UnregisterServiceWhileRegistering) {
ctx->waitForEvents();
}

TEST_F(CxxBundleContextTestSuite, GetServiceInEventLoop) {
auto context = ctx;
ctx->getFramework()->fireGenericEvent(
ctx->getBundleId(),
"register/unregister in Celix event thread",
[context]() {
auto tracker = context->trackServices<TestInterface>().build();
auto svc = tracker->getHighestRankingService();
EXPECT_TRUE(svc.get() == nullptr);
}
);
ctx->waitForEvents();
}

TEST_F(CxxBundleContextTestSuite, KeepSharedPtrActiveWhileDeregistering) {
auto svcReg = ctx->registerService<TestInterface>(std::make_shared<TestImplementation>())
.build();
@@ -653,4 +667,4 @@ TEST_F(CxxBundleContextTestSuite, CheckStandardServiceProperties) {
EXPECT_TRUE(called);

celix_bundleContext_unregisterService(ctx->getCBundleContext(), svcId);
}
}
@@ -159,7 +159,7 @@ namespace celix {
*/
void waitIfAble() const {
auto* fw = celix_bundleContext_getFramework(cCtx.get());
if (celix_framework_isCurrentThreadTheEventLoop(fw)) {
if (!celix_framework_isCurrentThreadTheEventLoop(fw)) {
wait();
}
}
@@ -765,4 +765,4 @@ namespace celix {
const std::vector<std::function<void(const ServiceTrackerInfo&)>> onTrackerDestroyed;
};

}
}

0 comments on commit 64b7293

Please sign in to comment.