diff --git a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc index bd2894d64..6f990cc3e 100644 --- a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc @@ -1664,6 +1664,40 @@ TEST_F(CelixBundleContextServicesTestSuite, StopSvcTrackerBeforeAsyncTrackerIsCr EXPECT_EQ(0, cbData.count.load()); //note create tracker canceled -> no callback } +TEST_F(CelixBundleContextServicesTestSuite, WaitForTrackerOnLoop) { + struct callback_data { + std::atomic count{}; + celix_bundle_context_t* ctx{nullptr}; + }; + callback_data cbData{}; + cbData.ctx = ctx; + + celix_framework_fireGenericEvent( + fw, + -1, + celix_bundle_getId(celix_framework_getFrameworkBundle(fw)), + "create tracker async", + (void*)&cbData, + [](void *data) { + auto cbd = static_cast(data); + + celix_service_tracking_options_t opts{}; + opts.filter.serviceName = "test-service"; + opts.trackerCreatedCallbackData = data; + opts.trackerCreatedCallback = [](void *data) { + auto* cbd = static_cast(data); + cbd->count.fetch_add(1); + }; + long trkId = celix_bundleContext_trackServicesWithOptions(cbd->ctx, &opts); + celix_bundleContext_waitForAsyncTracker(cbd->ctx, trkId); + celix_bundleContext_stopTracker(cbd->ctx, trkId); + }, + nullptr, + nullptr); + + celix_bundleContext_waitForEvents(ctx); +} + TEST_F(CelixBundleContextServicesTestSuite, StopBundleTrackerBeforeAsyncTrackerIsCreatedTest) { struct callback_data { std::atomic count{}; diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c index 252a014c5..612e940e8 100644 --- a/libs/framework/src/bundle_context.c +++ b/libs/framework/src/bundle_context.c @@ -952,6 +952,7 @@ static void celix_bundleContext_waitForTrackerInternal(celix_bundle_context_t* c CELIX_LOG_LEVEL_WARNING, "Cannot wait for tracker on the event loop thread. This can cause a deadlock. " "Ignoring call."); + return; } bool found = false;