Exemplo n.º 1
0
 def test_basic(self, time_):
     path_policy = MagicMock(spec_set=['history_limit'])
     path_policy.history_limit = 3
     pth_str = PathStore(path_policy)
     pth_str.candidates = [MagicMock(spec_set=['expiration_time', 'id'])
                           for i in range(5)]
     for i in range(5):
         pth_str.candidates[i].expiration_time = i
         pth_str.candidates[i].id = i
     time_.return_value = 2
     pth_str.remove_segments = MagicMock(spec_set=[])
     pth_str._remove_expired_segments()
     pth_str.remove_segments.assert_called_once_with([0, 1, 2])
Exemplo n.º 2
0
 def _setup(self):
     inst = PathStore("path_policy")
     inst._remove_expired_segments = create_mock()
     inst._update_all_fidelity = create_mock()
     inst.candidates = []
     for i, fidelity in enumerate([0, 5, 2, 6, 3]):
         candidate = create_mock(["pcb", "fidelity", "sending"])
         candidate.pcb = "pcb%d" % i
         candidate.fidelity = fidelity
         inst.candidates.append(candidate)
     return inst
Exemplo n.º 3
0
 def test_expire_paths(self, psi):
     """
     Test trimming the size of the candidate set by removing an expired
     segment.
     """
     pth_str = PathStore("path_policy")
     pth_str.path_policy = MagicMock(spec_set=['candidates_set_size'])
     pth_str.path_policy.candidates_set_size = 0
     pth_str.candidates = [0]
     pth_str._remove_expired_segments = (lambda: pth_str.candidates.pop())
     pth_str._trim_candidates()
     ntools.eq_(pth_str.candidates, [])
Exemplo n.º 4
0
 def test_remove_low_fidelity_path(self, psi):
     """
     Add a path, find that the candidate set size is too large, and remove
     the lowest-fidelity path.
     """
     pth_str = PathStore("path_policy")
     pth_str.path_policy = MagicMock(spec_set=['candidates_set_size'])
     pth_str.path_policy.candidates_set_size = 2
     pth_str.candidates = [create_mock(['fidelity']) for i in range(3)]
     pth_str.candidates[0].fidelity = 2
     pth_str.candidates[1].fidelity = 0
     pth_str.candidates[2].fidelity = 1
     remainder = [pth_str.candidates[0], pth_str.candidates[2]]
     pth_str._remove_expired_segments = create_mock()
     pth_str._update_all_fidelity = create_mock()
     pth_str._trim_candidates()
     pth_str._remove_expired_segments.assert_called_once_with()
     pth_str._update_all_fidelity.assert_called_once_with()
     ntools.eq_(pth_str.candidates, remainder)