Repository: tcalmant/ipopo

Issue:
RequiresVarFilter doesn't update bindings
When updating a property used in the filter of a RequiresVarFilter decorator on an invalid component instance, the bindings and the component lifecycle are not updated.

Current workaround: update `pelix.ipopo.handlers.requiresvarfilter::_VariableMixIn::_reset` to call `self._ipopo_instance.update_bindings()` after `self.start()` and `self._ipopo_instance.check_lifecycle()` after the bindings for loop.

Comments:

Patch:
diff --git a/pelix/ipopo/handlers/requiresvarfilter.py b/pelix/ipopo/handlers/requiresvarfilter.py
index a9895e0..133f51b 100644
--- a/pelix/ipopo/handlers/requiresvarfilter.py
+++ b/pelix/ipopo/handlers/requiresvarfilter.py
@@ -239,6 +239,9 @@ class _VariableFilterMixIn:
             self.stop()
             self.start()
 
+            # Force bindings update
+            self._ipopo_instance.update_bindings()
+
             for svc_ref in self.get_bindings():
                 # Check if the current reference matches the filter
                 if not self.requirement.filter.matches(


Test patch:
diff --git a/tests/ipopo/issue_119_bundle.py b/tests/ipopo/issue_119_bundle.py
new file mode 100644
index 0000000..669ba69
--- /dev/null
+++ b/tests/ipopo/issue_119_bundle.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# -- Content-Encoding: UTF-8 --
+"""
+Issue 119 (late binding issue on RequiresVarFilter) use case
+"""
+
+from pelix.ipopo.decorators import (
+    ComponentFactory,
+    Provides,
+    Property,
+    Requires,
+    RequiresVarFilter,
+)
+
+
+@ComponentFactory("provider-factory")
+@Property("providing", "providing", None)
+@Provides("required-service")
+class Provider:
+    def __init__(self):
+        self.providing = None
+
+
+@ComponentFactory("varservice-factory")
+@Property("search", "search")
+@RequiresVarFilter(
+    "depends", "required-service", spec_filter="(prop={search})"
+)
+class VarcConsumer:
+    def __init__(self):
+        self.depends = None
+        self.search = None
diff --git a/tests/ipopo/test_requires_varfilter.py b/tests/ipopo/test_requires_varfilter.py
index 7ed07ad..e54f16d 100644
--- a/tests/ipopo/test_requires_varfilter.py
+++ b/tests/ipopo/test_requires_varfilter.py
@@ -9,6 +9,9 @@ Tests the iPOPO @RequiresVarFilter decorator.
 # Standard library
 import random
 import string
+
+from pelix.ipopo.instance import StoredInstance
+
 try:
     import unittest2 as unittest
 except ImportError:
@@ -38,6 +41,7 @@ class RequiresVarFilterTest(unittest.TestCase):
     """
     Tests the "requires variable filter" handler behavior
     """
+
     def setUp(self):
         """
         Called before each test. Initiates a framework.
@@ -61,22 +65,30 @@ class RequiresVarFilterTest(unittest.TestCase):
         assert isinstance(context, BundleContext)
 
         # Prepare random string values
-        random_static_1 = ''.join(random.choice(string.ascii_letters)
-                                  for _ in range(50))
-        random_static_2 = ''.join(random.choice(string.ascii_letters)
-                                  for _ in range(50))
+        random_static_1 = "".join(
+            random.choice(string.ascii_letters) for _ in range(50)
+        )
+        random_static_2 = "".join(
+            random.choice(string.ascii_letters) for _ in range(50)
+        )
 
         # Assert that the service is not yet available
-        self.assertIsNone(context.get_service_reference(IEchoService),
-                          "Service is already registered")
+        self.assertIsNone(
+            context.get_service_reference(IEchoService),
+            "Service is already registered",
+        )
 
         # Instantiate the components
         consumer_single = self.ipopo.instantiate(
-            module.FACTORY_REQUIRES_VAR_FILTER, NAME_A,
-            {"static": random_static_1})
+            module.FACTORY_REQUIRES_VAR_FILTER,
+            NAME_A,
+            {"static": random_static_1},
+        )
         consumer_multi = self.ipopo.instantiate(
-            module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE, NAME_B,
-            {"static": random_static_1})
+            module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE,
+            NAME_B,
+            {"static": random_static_1},
+        )
         consumers = (consumer_single, consumer_multi)
 
         # Force the "answer" property to an int
@@ -85,46 +97,60 @@ class RequiresVarFilterTest(unittest.TestCase):
 
         # Component must be invalid
         for consumer in consumers:
-            self.assertListEqual([IPopoEvent.INSTANTIATED], consumer.states,
-                                 "Invalid component states: {0}"
-                                 .format(consumer.states))
+            self.assertListEqual(
+                [IPopoEvent.INSTANTIATED],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
 
         # Instantiate a service, matching the filter
         svc1 = object()
         context.register_service(
-            IEchoService, svc1,
-            {"s": random_static_1, "a": consumer_single.answer})
+            IEchoService,
+            svc1,
+            {"s": random_static_1, "a": consumer_single.answer},
+        )
 
         # The consumer must have been validated
         for consumer in consumers:
             self.assertListEqual(
-                [IPopoEvent.BOUND, IPopoEvent.VALIDATED], consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                [IPopoEvent.BOUND, IPopoEvent.VALIDATED],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
 
         self.assertIs(consumer_single.service, svc1, "Wrong service injected")
-        self.assertListEqual(consumer_multi.service, [svc1],
-                             "Wrong service injected")
+        self.assertListEqual(
+            consumer_multi.service, [svc1], "Wrong service injected"
+        )
 
         # New service, still matching
         svc2 = object()
         reg2 = context.register_service(
-            IEchoService, svc2,
-            {"s": random_static_1, "a": consumer_single.answer})
+            IEchoService,
+            svc2,
+            {"s": random_static_1, "a": consumer_single.answer},
+        )
 
         # The single consumer must not have been modified
-        self.assertListEqual([], consumer_single.states,
-                             "Invalid component states: {0}"
-                             .format(consumer_single.states))
+        self.assertListEqual(
+            [],
+            consumer_single.states,
+            "Invalid component states: {0}".format(consumer_single.states),
+        )
         self.assertIs(consumer_single.service, svc1, "Wrong service injected")
 
         # The aggregate consumer must have been modified
-        self.assertListEqual([IPopoEvent.BOUND], consumer_multi.states,
-                             "Invalid component states: {0}"
-                             .format(consumer_multi.states))
-        self.assertListEqual(consumer_multi.service, [svc1, svc2],
-                             "Second service not injected")
+        self.assertListEqual(
+            [IPopoEvent.BOUND],
+            consumer_multi.states,
+            "Invalid component states: {0}".format(consumer_multi.states),
+        )
+        self.assertListEqual(
+            consumer_multi.service, [svc1, svc2], "Second service not injected"
+        )
 
         # Reset states
         for consumer in consumers:
@@ -134,17 +160,22 @@ class RequiresVarFilterTest(unittest.TestCase):
         reg2.unregister()
 
         # The single consumer must not have been modified
-        self.assertListEqual([], consumer_single.states,
-                             "Invalid component states: {0}"
-                             .format(consumer_single.states))
+        self.assertListEqual(
+            [],
+            consumer_single.states,
+            "Invalid component states: {0}".format(consumer_single.states),
+        )
         self.assertIs(consumer_single.service, svc1, "Wrong service injected")
 
         # The aggregate consumer must have been modified
-        self.assertListEqual([IPopoEvent.UNBOUND], consumer_multi.states,
-                             "Invalid component states: {0}"
-                             .format(consumer_multi.states))
-        self.assertListEqual(consumer_multi.service, [svc1],
-                             "Second service not removed")
+        self.assertListEqual(
+            [IPopoEvent.UNBOUND],
+            consumer_multi.states,
+            "Invalid component states: {0}".format(consumer_multi.states),
+        )
+        self.assertListEqual(
+            consumer_multi.service, [svc1], "Second service not removed"
+        )
 
         # Change the filter property to the exact same value
         for consumer in consumers:
@@ -152,14 +183,17 @@ class RequiresVarFilterTest(unittest.TestCase):
             consumer.change(42)
 
             # The consumer must not have been modified
-            self.assertListEqual([], consumer.states,
-                                 "Invalid component states: {0}"
-                                 .format(consumer.states))
+            self.assertListEqual(
+                [],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
 
         self.assertIs(consumer_single.service, svc1, "Wrong service injected")
-        self.assertListEqual(consumer_multi.service, [svc1],
-                             "Wrong service injected")
+        self.assertListEqual(
+            consumer_multi.service, [svc1], "Wrong service injected"
+        )
 
         # Change the filter property to a new value
         for consumer in consumers:
@@ -170,60 +204,76 @@ class RequiresVarFilterTest(unittest.TestCase):
             self.assertListEqual(
                 [IPopoEvent.INVALIDATED, IPopoEvent.UNBOUND],
                 consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                "Invalid component states: {0}".format(consumer.states),
+            )
             self.assertIs(consumer.service, None, "A service is injected")
             consumer.reset()
 
         # New service, matching part of the filter
         svc3 = object()
         context.register_service(
-            IEchoService, svc3,
-            {"s": random_static_2, "a": consumer_single.answer})
+            IEchoService,
+            svc3,
+            {"s": random_static_2, "a": consumer_single.answer},
+        )
 
         # The consumer must not have been modified
         for consumer in consumers:
-            self.assertListEqual([], consumer.states,
-                                 "Invalid component states: {0}"
-                                 .format(consumer.states))
+            self.assertListEqual(
+                [],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             self.assertIs(consumer.service, None, "A service is injected")
             consumer.reset()
 
         # New service, matching the new filer
         svc4 = object()
         reg4 = context.register_service(
-            IEchoService, svc4,
-            {"s": random_static_1, "a": consumer_single.answer})
+            IEchoService,
+            svc4,
+            {"s": random_static_1, "a": consumer_single.answer},
+        )
 
         # The consumer must not have been modified
         for consumer in consumers:
             self.assertListEqual(
                 [IPopoEvent.BOUND, IPopoEvent.VALIDATED],
                 consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
 
         self.assertIs(consumer_single.service, svc4, "Wrong service injected")
-        self.assertListEqual(consumer_multi.service, [svc4],
-                             "Wrong service injected")
+        self.assertListEqual(
+            consumer_multi.service, [svc4], "Wrong service injected"
+        )
 
         # New service, matching the new filer
         svc5 = object()
         reg5 = context.register_service(
-            IEchoService, svc5,
-            {"s": random_static_1, "a": consumer_single.answer})
+            IEchoService,
+            svc5,
+            {"s": random_static_1, "a": consumer_single.answer},
+        )
 
         # The single consumer must not have been modified
-        self.assertListEqual([], consumer_single.states,
-                             "Invalid component states: {0}"
-                             .format(consumer_single.states))
+        self.assertListEqual(
+            [],
+            consumer_single.states,
+            "Invalid component states: {0}".format(consumer_single.states),
+        )
         self.assertIs(consumer_single.service, svc4, "Wrong service injected")
 
         # The aggregate consumer must have been modified
-        self.assertListEqual([IPopoEvent.BOUND], consumer_multi.states,
-                             "Invalid component states: {0}"
-                             .format(consumer_multi.states))
-        self.assertListEqual(consumer_multi.service, [svc4, svc5],
-                             "Second service not injected")
+        self.assertListEqual(
+            [IPopoEvent.BOUND],
+            consumer_multi.states,
+            "Invalid component states: {0}".format(consumer_multi.states),
+        )
+        self.assertListEqual(
+            consumer_multi.service, [svc4, svc5], "Second service not injected"
+        )
 
         # Reset states
         for consumer in consumers:
@@ -236,15 +286,19 @@ class RequiresVarFilterTest(unittest.TestCase):
         self.assertListEqual(
             rebind_states,
             consumer_single.states,
-            "Invalid component states: {0}".format(consumer_single.states))
+            "Invalid component states: {0}".format(consumer_single.states),
+        )
         self.assertIs(consumer_single.service, svc5, "Wrong service injected")
 
         # The aggregate consumer must have been modified
-        self.assertListEqual([IPopoEvent.UNBOUND], consumer_multi.states,
-                             "Invalid component states: {0}"
-                             .format(consumer_multi.states))
-        self.assertListEqual(consumer_multi.service, [svc5],
-                             "First service not removed")
+        self.assertListEqual(
+            [IPopoEvent.UNBOUND],
+            consumer_multi.states,
+            "Invalid component states: {0}".format(consumer_multi.states),
+        )
+        self.assertListEqual(
+            consumer_multi.service, [svc5], "First service not removed"
+        )
 
         # Reset states
         for consumer in consumers:
@@ -255,8 +309,10 @@ class RequiresVarFilterTest(unittest.TestCase):
 
         for consumer in consumers:
             self.assertListEqual(
-                [IPopoEvent.INVALIDATED, IPopoEvent.UNBOUND], consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                [IPopoEvent.INVALIDATED, IPopoEvent.UNBOUND],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             self.assertIs(consumer.service, None, "A service is still injected")
             consumer.reset()
 
@@ -265,9 +321,15 @@ class RequiresVarFilterTest(unittest.TestCase):
         Tests the @RequiresVarFilter handler without immediate_rebind (default)
         """
         module = install_bundle(self.framework)
-        self.__internal_test(module,
-                             [IPopoEvent.INVALIDATED, IPopoEvent.UNBOUND,
-                              IPopoEvent.BOUND, IPopoEvent.VALIDATED])
+        self.__internal_test(
+            module,
+            [
+                IPopoEvent.INVALIDATED,
+                IPopoEvent.UNBOUND,
+                IPopoEvent.BOUND,
+                IPopoEvent.VALIDATED,
+            ],
+        )
 
     def test_immediate_rebind(self):
         """
@@ -276,8 +338,10 @@ class RequiresVarFilterTest(unittest.TestCase):
         # Modify component factories
         module = install_bundle(self.framework)
 
-        for clazz in (module.RequiresVarFilterComponentFactory,
-                      module.RequiresVarFilterAggregateComponentFactory):
+        for clazz in (
+            module.RequiresVarFilterComponentFactory,
+            module.RequiresVarFilterAggregateComponentFactory,
+        ):
             context = get_factory_context(clazz)
             configs = context.get_handler(RequiresVarFilter.HANDLER_ID)
             configs["service"].immediate_rebind = True
@@ -292,20 +356,27 @@ class RequiresVarFilterTest(unittest.TestCase):
         context = self.framework.get_bundle_context()
         assert isinstance(context, BundleContext)
 
-        random_static = ''.join(random.choice(string.ascii_letters)
-                                for _ in range(50))
+        random_static = "".join(
+            random.choice(string.ascii_letters) for _ in range(50)
+        )
 
         # Assert that the service is not yet available
-        self.assertIsNone(context.get_service_reference(IEchoService),
-                          "Service is already registered")
+        self.assertIsNone(
+            context.get_service_reference(IEchoService),
+            "Service is already registered",
+        )
 
         # Instantiate the components
         consumer_single = self.ipopo.instantiate(
-            module.FACTORY_REQUIRES_VAR_FILTER, NAME_A,
-            {"static": random_static})
+            module.FACTORY_REQUIRES_VAR_FILTER,
+            NAME_A,
+            {"static": random_static},
+        )
         consumer_multi = self.ipopo.instantiate(
-            module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE, NAME_B,
-            {"static": random_static})
+            module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE,
+            NAME_B,
+            {"static": random_static},
+        )
         consumers = (consumer_single, consumer_multi)
 
         # Force the "answer" property to an int
@@ -315,15 +386,22 @@ class RequiresVarFilterTest(unittest.TestCase):
         # Instantiate a service, matching the filter
         svc1 = object()
         context.register_service(
-            IEchoService, svc1,
-            {"s": random_static, "a": consumer_single.answer})
+            IEchoService,
+            svc1,
+            {"s": random_static, "a": consumer_single.answer},
+        )
 
         # Component must be valid
         for consumer in consumers:
             self.assertListEqual(
-                [IPopoEvent.INSTANTIATED, IPopoEvent.BOUND,
-                 IPopoEvent.VALIDATED], consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                [
+                    IPopoEvent.INSTANTIATED,
+                    IPopoEvent.BOUND,
+                    IPopoEvent.VALIDATED,
+                ],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
 
         # Set an invalid filter
@@ -332,8 +410,10 @@ class RequiresVarFilterTest(unittest.TestCase):
 
             # The consumer must have been validated
             self.assertListEqual(
-                [IPopoEvent.INVALIDATED, IPopoEvent.UNBOUND], consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                [IPopoEvent.INVALIDATED, IPopoEvent.UNBOUND],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
             self.assertIs(consumer.service, None, "A service is injected")
 
@@ -346,12 +426,15 @@ class RequiresVarFilterTest(unittest.TestCase):
                 # Instantiate a service, matching the filter
                 svc = object()
                 reg = context.register_service(
-                    IEchoService, svc, {"s": random_static, "a": invalid})
+                    IEchoService, svc, {"s": random_static, "a": invalid}
+                )
 
                 # Nothing should happen
                 self.assertListEqual(
-                    [], consumer.states,
-                    "Invalid component states: {0}".format(consumer.states))
+                    [],
+                    consumer.states,
+                    "Invalid component states: {0}".format(consumer.states),
+                )
                 consumer.reset()
 
                 reg.unregister()
@@ -365,20 +448,27 @@ class RequiresVarFilterTest(unittest.TestCase):
         context = self.framework.get_bundle_context()
         assert isinstance(context, BundleContext)
 
-        random_static = ''.join(random.choice(string.ascii_letters)
-                                for _ in range(50))
+        random_static = "".join(
+            random.choice(string.ascii_letters) for _ in range(50)
+        )
 
         # Assert that the service is not yet available
-        self.assertIsNone(context.get_service_reference(IEchoService),
-                          "Service is already registered")
+        self.assertIsNone(
+            context.get_service_reference(IEchoService),
+            "Service is already registered",
+        )
 
         # Instantiate the components
         consumer_single = self.ipopo.instantiate(
-            module.FACTORY_REQUIRES_VAR_FILTER, NAME_A,
-            {"static": random_static})
+            module.FACTORY_REQUIRES_VAR_FILTER,
+            NAME_A,
+            {"static": random_static},
+        )
         consumer_multi = self.ipopo.instantiate(
-            module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE, NAME_B,
-            {"static": random_static})
+            module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE,
+            NAME_B,
+            {"static": random_static},
+        )
         consumers = (consumer_single, consumer_multi)
 
         # Force the "answer" property to an int
@@ -388,15 +478,22 @@ class RequiresVarFilterTest(unittest.TestCase):
         # Instantiate a service, matching the filter
         svc1 = object()
         context.register_service(
-            IEchoService, svc1,
-            {"s": random_static, "a": consumer_single.answer})
+            IEchoService,
+            svc1,
+            {"s": random_static, "a": consumer_single.answer},
+        )
 
         # Component must be valid
         for consumer in consumers:
             self.assertListEqual(
-                [IPopoEvent.INSTANTIATED, IPopoEvent.BOUND,
-                 IPopoEvent.VALIDATED], consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                [
+                    IPopoEvent.INSTANTIATED,
+                    IPopoEvent.BOUND,
+                    IPopoEvent.VALIDATED,
+                ],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
 
         # Set the filter with a similar value (same once formatted)
@@ -406,13 +503,16 @@ class RequiresVarFilterTest(unittest.TestCase):
         # The consumer should not be notified
         for consumer in consumers:
             self.assertListEqual(
-                [], consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                [],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             consumer.reset()
 
         self.assertIs(consumer_single.service, svc1, "Wrong service injected")
-        self.assertListEqual(consumer_multi.service, [svc1],
-                             "Wrong service injected")
+        self.assertListEqual(
+            consumer_multi.service, [svc1], "Wrong service injected"
+        )
 
     def test_incomplete_properties(self):
         """
@@ -423,21 +523,26 @@ class RequiresVarFilterTest(unittest.TestCase):
         assert isinstance(context, BundleContext)
 
         answer = 42
-        random_static = ''.join(random.choice(string.ascii_letters)
-                                for _ in range(50))
+        random_static = "".join(
+            random.choice(string.ascii_letters) for _ in range(50)
+        )
 
         # Assert that the service is not yet available
-        self.assertIsNone(context.get_service_reference(IEchoService),
-                          "Service is already registered")
+        self.assertIsNone(
+            context.get_service_reference(IEchoService),
+            "Service is already registered",
+        )
 
         # Instantiate a service, matching the filter
         svc1 = object()
         context.register_service(
-            IEchoService, svc1, {"s": random_static, "a": answer})
+            IEchoService, svc1, {"s": random_static, "a": answer}
+        )
 
         for name, factory in (
-                (NAME_A, module.FACTORY_REQUIRES_VAR_FILTER),
-                (NAME_B, module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE)):
+            (NAME_A, module.FACTORY_REQUIRES_VAR_FILTER),
+            (NAME_B, module.FACTORY_REQUIRES_VAR_FILTER_AGGREGATE),
+        ):
             # Instantiate the component, without the static property
             consumer = self.ipopo.instantiate(factory, name, {})
 
@@ -446,14 +551,59 @@ class RequiresVarFilterTest(unittest.TestCase):
 
             # Component must be instantiated, but not valid
             self.assertListEqual(
-                [IPopoEvent.INSTANTIATED], consumer.states,
-                "Invalid component states: {0}".format(consumer.states))
+                [IPopoEvent.INSTANTIATED],
+                consumer.states,
+                "Invalid component states: {0}".format(consumer.states),
+            )
             self.assertIs(consumer.service, None, "Service injected")
 
+    def test_late_binding(self):
+        """
+        Tests late binding, see issue #119:
+        https://github.com/tcalmant/ipopo/issues/119
+        """
+        install_bundle(self.framework, "tests.ipopo.issue_119_bundle")
+        context = self.framework.get_bundle_context()
+        assert isinstance(context, BundleContext)
+
+        self.ipopo.instantiate("varservice-factory", "varservice-instance")
+        self.ipopo.instantiate("provider-factory", "provider-instance-1", {"prop": "svc1"})
+        self.ipopo.instantiate("provider-factory", "provider-instance-2", {"prop": "svc2"})
+
+        svc1 =  self.ipopo.get_instance("provider-instance-1")
+        svc2 =  self.ipopo.get_instance("provider-instance-2")
+        consumer =  self.ipopo.get_instance("varservice-instance")
+
+        self.assertEqual(self.ipopo.get_instance_details("provider-instance-1")["state"], StoredInstance.VALID)
+        self.assertEqual(self.ipopo.get_instance_details("provider-instance-2")["state"], StoredInstance.VALID)
+        self.assertEqual(self.ipopo.get_instance_details("varservice-instance")["state"], StoredInstance.INVALID)
+
+        consumer.search = "svc1"
+        self.assertEqual(self.ipopo.get_instance_details("varservice-instance")["state"], StoredInstance.VALID)
+        self.assertEqual(consumer.depends, svc1)
+
+        consumer.search = "svc2"
+        self.assertEqual(self.ipopo.get_instance_details("varservice-instance")["state"], StoredInstance.VALID)
+        self.assertEqual(consumer.depends, svc2)
+
+        consumer.search = "non-existent"
+        self.assertEqual(self.ipopo.get_instance_details("varservice-instance")["state"], StoredInstance.INVALID)
+        self.assertIsNone(consumer.depends)
+
+        consumer.search = "svc1"
+        self.assertEqual(self.ipopo.get_instance_details("varservice-instance")["state"], StoredInstance.VALID)
+        self.assertEqual(consumer.depends, svc1)
+
+        consumer.search = None
+        self.assertEqual(self.ipopo.get_instance_details("varservice-instance")["state"], StoredInstance.INVALID)
+        self.assertIsNone(consumer.depends)
+
+
 # ------------------------------------------------------------------------------
 
 if __name__ == "__main__":
     # Set logging level
     import logging
+
     logging.basicConfig(level=logging.DEBUG)
     unittest.main()