def test_transit_set(self): view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0) pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0) # All is well view_est_mod.get_phs = MagicMock(return_value=0) pred_module.stale_v = MagicMock(return_value=False) pred_module.transition_cases = MagicMock(return_value=True) self.assertEqual( pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW), {0, 1}) # Different phases, node 0 in phase 1 and node 1 in phase 0 view_est_mod.get_phs = MagicMock(side_effect=lambda x: (x + 1) % 2) self.assertEqual( pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW), {1}) # Transition case returns false view_est_mod.get_phs = MagicMock(return_value=0) pred_module.transition_cases = MagicMock(return_value=False) self.assertEqual( pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW), set()) # Both processors are stale pred_module.stale_v = MagicMock(return_value=True) pred_module.transition_cases = MagicMock(return_value=True) self.assertEqual( pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW), set())
def test_transition_cases(self): view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0) pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0) view_pair_to_test = {CURRENT: 0, NEXT: 1} # Mode REMAIN both phases, one pred_module.views[pred_module.id].update({CURRENT: 1, NEXT: 1}) self.assertTrue( pred_module.transition_cases(0, view_pair_to_test, 0, ViewEstablishmentEnums.REMAIN)) pred_module.views[pred_module.id].update({CURRENT: 0, NEXT: 0}) self.assertFalse( pred_module.transition_cases(0, view_pair_to_test, 1, ViewEstablishmentEnums.REMAIN)) # Mode FOLLOW, phase 0 should return true self.assertTrue( pred_module.transition_cases(0, view_pair_to_test, 0, ViewEstablishmentEnums.FOLLOW)) # Mode FOLLOW, phase 0 should return false pred_module.views[pred_module.id].update({CURRENT: 1, NEXT: 1}) self.assertFalse( pred_module.transition_cases(0, view_pair_to_test, 0, ViewEstablishmentEnums.FOLLOW)) # Mode FOLLOW, phase 1 should return false self.assertFalse( pred_module.transition_cases(0, view_pair_to_test, 1, ViewEstablishmentEnums.FOLLOW)) # Mode FOLLOW, phase 1 should return true pred_module.views[pred_module.id].update({CURRENT: 0, NEXT: 0}) self.assertTrue( pred_module.transition_cases(0, view_pair_to_test, 1, ViewEstablishmentEnums.FOLLOW))