def test_isolation(self): """ Test the in_isolation method. """ from supvisors.address import AddressStatus from supvisors.ttypes import AddressStates status = AddressStatus('10.0.0.1', self.supvisors.logger) for state in self.all_states: status._state = state self.assertTrue(status.in_isolation() and state in [AddressStates.ISOLATING, AddressStates.ISOLATED] or not status.in_isolation() and state not in [AddressStates.ISOLATING, AddressStates.ISOLATED])
def test_transitions(self): """ Test the state transitions of AddressStatus. """ from supvisors.address import AddressStatus from supvisors.ttypes import AddressStates, InvalidTransition status = AddressStatus('10.0.0.1', self.supvisors.logger) for state1 in self.all_states: for state2 in self.all_states: # check all possible transitions from each state status._state = state1 if state2 in status._Transitions[state1]: status.state = state2 self.assertEqual(state2, status.state) self.assertEqual(AddressStates._to_string(state2), status.state_string()) elif state1 == state2: self.assertEqual(state1, status.state) else: with self.assertRaises(InvalidTransition): status.state = state2
def test_serialization(self): """ Test the serial method used to get a serializable form of AddressStatus. """ import pickle from supvisors.address import AddressStatus from supvisors.ttypes import AddressStates # create address status instance status = AddressStatus('10.0.0.1', self.supvisors.logger) status._state = AddressStates.RUNNING status.checked = True status.remote_time = 50 status.local_time = 60 # test to_json method serialized = status.serial() self.assertDictEqual(serialized, {'address_name': '10.0.0.1', 'loading': 0, 'statecode': 2, 'statename': 'RUNNING', 'remote_time': 50, 'local_time':60}) # test that returned structure is serializable using pickle dumped = pickle.dumps(serialized) loaded = pickle.loads(dumped) self.assertDictEqual(serialized, loaded)