You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2020/09/08 18:50:12 UTC

[celix] 01/02: Adds test for dynamically creating and destroying a component providing a remote service which deadlocks

This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch hotfix/rsa_deadlock
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 333b8749cae748530dde7b33d17482e115645f8b
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Tue Sep 8 18:26:21 2020 +0200

    Adds test for dynamically creating and destroying a component providing a remote service which deadlocks
---
 .../gtest/src/rsa_client_server_tests.cc           | 12 +++++++++++
 .../gtest/src/tst_activator.c                      | 24 ++++++++++++++++++++++
 .../gtest/src/tst_service.h                        |  1 +
 3 files changed, 37 insertions(+)

diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc
index 9c42951..b8ef8f0 100644
--- a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc
+++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc
@@ -136,6 +136,13 @@ extern "C" {
         ASSERT_TRUE(ok);
     };
 
+    static void testCreateDestroyComponentWithRemoteService(void *handle __attribute__((unused)), void *svc) {
+        auto *tst = static_cast<tst_service_t *>(svc);
+
+        bool ok = tst->testCreateDestroyComponentWithRemoteService(tst->handle);
+        ASSERT_TRUE(ok);
+    };
+
 }
 
 template<typename F>
@@ -188,3 +195,8 @@ TEST_F(RsaDfiClientServerTests, TestRemoteEnum) {
 TEST_F(RsaDfiClientServerTests, TestRemoteAction) {
     test(testAction);
 }
+
+TEST_F(RsaDfiClientServerTests, CreateDestroyComponentWithRemoteService) {
+    test(testCreateDestroyComponentWithRemoteService);
+}
+
diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_activator.c b/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_activator.c
index 6385dde..3724755 100644
--- a/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_activator.c
+++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_activator.c
@@ -40,6 +40,7 @@
     } while(0)
 
 struct activator {
+    celix_bundle_context_t *ctx;
     long svcId;
     struct tst_service testSvc;
 
@@ -269,8 +270,30 @@ static bool bndTestRemoteComplex(void *handle) {
     return ok;
 }
 
+static bool bndTestCreateDestroyComponentWithRemoteService(void *handle) {
+    struct activator *act = handle;
+
+    celix_properties_t *properties = celix_properties_create();
+    celix_properties_set(properties, "service.exported.interfaces", CALCULATOR_SERVICE);
+
+    calculator_service_t calcSvc;
+    calcSvc.handle = NULL;
+    calcSvc.add = NULL; //note for this test case the actual services can be NULL
+    calcSvc.sub = NULL; //note for this test case the actual services can be NULL
+    calcSvc.sqrt = NULL; //note for this test case the actual services can be NULL
+
+    celix_dm_component_t *cmp = celix_dmComponent_create(act->ctx, "test");
+    celix_dmComponent_addInterface(cmp, CALCULATOR_SERVICE, NULL, &calcSvc, properties);
+
+    celix_dependency_manager_t *dm = celix_bundleContext_getDependencyManager(act->ctx);
+    dependencyManager_add(dm, cmp);
+    dependencyManager_removeAllComponents(dm); //note should not deadlock
+    return true;
+}
+
 static celix_status_t bndStart(struct activator *act, celix_bundle_context_t* ctx) {
     //initialize service struct
+    act->ctx = ctx;
     act->testSvc.handle = act;
     act->testSvc.isCalcDiscovered = bndIsCalculatorDiscovered;
     act->testSvc.isRemoteExampleDiscovered = bndIsRemoteExampleDiscovered;
@@ -281,6 +304,7 @@ static celix_status_t bndStart(struct activator *act, celix_bundle_context_t* ct
     act->testSvc.testRemoteEnum = bndTestRemoteEnum;
     act->testSvc.testRemoteAction = bndTestRemoteAction;
     act->testSvc.testRemoteComplex = bndTestRemoteComplex;
+    act->testSvc.testCreateDestroyComponentWithRemoteService = bndTestCreateDestroyComponentWithRemoteService;
 
 
     //create mutex
diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_service.h b/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_service.h
index 596ab63..9dab7c1 100644
--- a/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_service.h
+++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_service.h
@@ -33,6 +33,7 @@ struct tst_service {
     bool (*testRemoteEnum)(void *handle);
     bool (*testRemoteAction)(void *handle);
     bool (*testRemoteComplex)(void *handle);
+    bool (*testCreateDestroyComponentWithRemoteService)(void *handle);
 };
 
 typedef struct tst_service tst_service_t;