Beispiel #1
0
    def test_lookup_some_pending_some_contacted(self):
        """
        Ensures the _lookup method works with some pending slots available and
        some nodes previously contacted.
        """
        lookup = Lookup(FindValue, self.target, self.node, self.event_loop)
        # Reset in order to manually create the correct state.
        lookup.pending_requests = {}
        lookup.contacted = set()
        self.node.send_find.call_count = 0

        # Add a single pending request.
        pending_uuid = str(uuid.uuid4())
        pending_future = asyncio.Future()
        lookup.pending_requests[pending_uuid] = pending_future
        # Add a single contact to the contacted list.
        lookup.contacted.add(lookup.shortlist[0])
        # Sanity check.
        self.assertEqual(1, len(lookup.pending_requests))
        self.assertEqual(1, len(lookup.contacted))
        # Re-run _lookup and check state has been correctly updated.
        lookup._lookup()
        self.assertEqual(ALPHA - 1, self.node.send_find.call_count)
        self.assertEqual(ALPHA, len(lookup.pending_requests))
        self.assertEqual(ALPHA, len(lookup.contacted))
Beispiel #2
0
    def test_lookup_some_pending_some_contacted(self):
        """
        Ensures the _lookup method works with some pending slots available and
        some nodes previously contacted.
        """
        lookup = Lookup(FindValue, self.target, self.node, self.event_loop)
        # Reset in order to manually create the correct state.
        lookup.pending_requests = {}
        lookup.contacted = set()
        self.node.send_find.call_count = 0

        # Add a single pending request.
        pending_uuid = str(uuid.uuid4())
        pending_future = asyncio.Future()
        lookup.pending_requests[pending_uuid] = pending_future
        # Add a single contact to the contacted list.
        lookup.contacted.add(lookup.shortlist[0])
        # Sanity check.
        self.assertEqual(1, len(lookup.pending_requests))
        self.assertEqual(1, len(lookup.contacted))
        # Re-run _lookup and check state has been correctly updated.
        lookup._lookup()
        self.assertEqual(ALPHA - 1, self.node.send_find.call_count)
        self.assertEqual(ALPHA, len(lookup.pending_requests))
        self.assertEqual(ALPHA, len(lookup.contacted))
Beispiel #3
0
 def test_lookup_none_pending_all_contacted(self):
     """
     Ensures the _lookup method works with no pending requests and all known
     peer nodes having been contacted.
     """
     lookup = Lookup(FindValue, self.target, self.node, self.event_loop)
     # Put the lookup object in the state to test.
     lookup.pending_requests = {}
     for contact in lookup.shortlist:
         lookup.contacted.add(contact)
     self.node.send_find.call_count = 0
     # Re-run _lookup and test
     lookup._lookup()
     self.assertEqual(self.node.send_find.call_count, 0)
Beispiel #4
0
 def test_lookup_none_pending_all_contacted(self):
     """
     Ensures the _lookup method works with no pending requests and all known
     peer nodes having been contacted.
     """
     lookup = Lookup(FindValue, self.target, self.node, self.event_loop)
     # Put the lookup object in the state to test.
     lookup.pending_requests = {}
     for contact in lookup.shortlist:
         lookup.contacted.add(contact)
     self.node.send_find.call_count = 0
     # Re-run _lookup and test
     lookup._lookup()
     self.assertEqual(self.node.send_find.call_count, 0)