예제 #1
0
 def test_setdefault_process(self):
     """ Test the access / creation of a process status. """
     from supvisors.context import Context
     context = Context(self.supvisors)
     # check application list
     self.assertDictEqual({}, context.applications)
     self.assertDictEqual({}, context.processes)
     # get process
     dummy_info1 = {'group': 'dummy_application_1', 'name': 'dummy_process_1'}
     process1 = context.setdefault_process(dummy_info1)
     # check application and process list
     self.assertItemsEqual(['dummy_application_1'], context.applications.keys())
     self.assertDictEqual({'dummy_application_1:dummy_process_1': process1}, context.processes)
     # get application
     dummy_info2 = {'group': 'dummy_application_2', 'name': 'dummy_process_2'}
     process2 = context.setdefault_process(dummy_info2)
     # check application and process list
     self.assertItemsEqual(['dummy_application_1', 'dummy_application_2'],
         context.applications.keys())
     self.assertDictEqual({'dummy_application_1:dummy_process_1': process1,
         'dummy_application_2:dummy_process_2': process2},
         context.processes)
     # get application
     dummy_info3 = {'group': process1.application_name, 'name': process1.process_name}
     process3 = context.setdefault_process(dummy_info3)
     self.assertIs(process1, process3)
     # check application and process list
     self.assertItemsEqual(['dummy_application_1', 'dummy_application_2'],
         context.applications.keys())
     self.assertDictEqual({'dummy_application_1:dummy_process_1': process1,
         'dummy_application_2:dummy_process_2': process2},
         context.processes)
예제 #2
0
 def test_setdefault_process(self):
     """ Test the access / creation of a process status. """
     from supvisors.context import Context
     context = Context(self.supvisors)
     # check application list
     self.assertDictEqual({}, context.applications)
     self.assertDictEqual({}, context.processes)
     # get process
     dummy_info1 = {
         'group': 'dummy_application_1',
         'name': 'dummy_process_1'
     }
     process1 = context.setdefault_process(dummy_info1)
     # check application and process list
     self.assertItemsEqual(['dummy_application_1'],
                           context.applications.keys())
     self.assertDictEqual({'dummy_application_1:dummy_process_1': process1},
                          context.processes)
     # get application
     dummy_info2 = {
         'group': 'dummy_application_2',
         'name': 'dummy_process_2'
     }
     process2 = context.setdefault_process(dummy_info2)
     # check application and process list
     self.assertItemsEqual(['dummy_application_1', 'dummy_application_2'],
                           context.applications.keys())
     self.assertDictEqual(
         {
             'dummy_application_1:dummy_process_1': process1,
             'dummy_application_2:dummy_process_2': process2
         }, context.processes)
     # get application
     dummy_info3 = {
         'group': process1.application_name,
         'name': process1.process_name
     }
     process3 = context.setdefault_process(dummy_info3)
     self.assertIs(process1, process3)
     # check application and process list
     self.assertItemsEqual(['dummy_application_1', 'dummy_application_2'],
                           context.applications.keys())
     self.assertDictEqual(
         {
             'dummy_application_1:dummy_process_1': process1,
             'dummy_application_2:dummy_process_2': process2
         }, context.processes)
예제 #3
0
 def test_process_event(self):
     """ Test the handling of a process event. """
     from supvisors.context import Context
     from supvisors.ttypes import AddressStates, ApplicationStates
     context = Context(self.supvisors)
     with patch.object(self.supvisors.zmq.publisher, 'send_application_status') as mocked_appli:
         with patch.object(self.supvisors.zmq.publisher, 'send_process_status') as mocked_proc:
             # check no exception with unknown address
             result = context.on_process_event('10.0.0.0', {})
             self.assertIsNone(result)
             self.assertEqual(0, mocked_appli.call_count)
             self.assertEqual(0, mocked_proc.call_count)
             # get address status used for tests
             address = context.addresses['10.0.0.1']
             # check no change with known address in isolation
             for state in [AddressStates.ISOLATING, AddressStates.ISOLATED]:
                 address._state = state
                 result = context.on_process_event('10.0.0.1', {})
                 self.assertIsNone(result)
                 self.assertEqual(0, mocked_appli.call_count)
                 self.assertEqual(0, mocked_proc.call_count)
             # check no exception with unknown process
             for state in [AddressStates.UNKNOWN, AddressStates.SILENT, AddressStates.CHECKING, AddressStates.RUNNING]:
                 address._state = state
                 result = context.on_process_event('10.0.0.1', {'groupname': 'dummy_application', 'processname': 'dummy_process'})
                 self.assertIsNone(result)
                 self.assertEqual(0, mocked_appli.call_count)
                 self.assertEqual(0, mocked_proc.call_count)
             # fill context with one process
             dummy_info = {'group': 'dummy_application', 'name': 'dummy_process', 'expected': True, 'now': 1234, 'state': 0}
             process = context.setdefault_process(dummy_info)
             process.add_info('10.0.0.1', dummy_info)
             application = context.applications['dummy_application']
             self.assertEqual(ApplicationStates.STOPPED, application.state)
             # check normal behaviour with known process
             dummy_event = {'group': 'dummy_application', 'name': 'dummy_process', 'state': 10, 'now': 2345}
             for state in [AddressStates.UNKNOWN, AddressStates.SILENT, AddressStates.CHECKING, AddressStates.RUNNING]:
                 address._state = state
                 result = context.on_process_event('10.0.0.1', dummy_event)
                 self.assertIs(process, result)
                 self.assertEqual(10, process.state)
                 self.assertEqual(ApplicationStates.STARTING, application.state)
                 self.assertEqual(call(application), mocked_appli.call_args)
                 self.assertEqual(call(process), mocked_proc.call_args)
예제 #4
0
 def test_process_event(self):
     """ Test the handling of a process event. """
     from supvisors.context import Context
     from supvisors.ttypes import AddressStates, ApplicationStates
     context = Context(self.supvisors)
     with patch.object(self.supvisors.zmq.publisher,
                       'send_application_status') as mocked_appli:
         with patch.object(self.supvisors.zmq.publisher,
                           'send_process_status') as mocked_proc:
             # check no exception with unknown address
             result = context.on_process_event('10.0.0.0', {})
             self.assertIsNone(result)
             self.assertEqual(0, mocked_appli.call_count)
             self.assertEqual(0, mocked_proc.call_count)
             # get address status used for tests
             address = context.addresses['10.0.0.1']
             # check no change with known address in isolation
             for state in [AddressStates.ISOLATING, AddressStates.ISOLATED]:
                 address._state = state
                 result = context.on_process_event('10.0.0.1', {})
                 self.assertIsNone(result)
                 self.assertEqual(0, mocked_appli.call_count)
                 self.assertEqual(0, mocked_proc.call_count)
             # check no exception with unknown process
             for state in [
                     AddressStates.UNKNOWN, AddressStates.SILENT,
                     AddressStates.CHECKING, AddressStates.RUNNING
             ]:
                 address._state = state
                 result = context.on_process_event(
                     '10.0.0.1', {
                         'groupname': 'dummy_application',
                         'processname': 'dummy_process'
                     })
                 self.assertIsNone(result)
                 self.assertEqual(0, mocked_appli.call_count)
                 self.assertEqual(0, mocked_proc.call_count)
             # fill context with one process
             dummy_info = {
                 'group': 'dummy_application',
                 'name': 'dummy_process',
                 'spawnerr': '',
                 'now': 1234,
                 'state': 0
             }
             process = context.setdefault_process(dummy_info)
             process.add_info('10.0.0.1', dummy_info)
             application = context.applications['dummy_application']
             self.assertEqual(ApplicationStates.STOPPED, application.state)
             # check normal behaviour with known process
             dummy_event = {
                 'groupname': 'dummy_application',
                 'processname': 'dummy_process',
                 'state': 10,
                 'now': 2345
             }
             for state in [
                     AddressStates.UNKNOWN, AddressStates.SILENT,
                     AddressStates.CHECKING, AddressStates.RUNNING
             ]:
                 address._state = state
                 result = context.on_process_event('10.0.0.1', dummy_event)
                 self.assertIs(process, result)
                 self.assertEqual(10, process.state)
                 self.assertEqual(2345, process.last_event_time)
                 self.assertEqual(ApplicationStates.STARTING,
                                  application.state)
                 self.assertEqual(call(application), mocked_appli.call_args)
                 self.assertEqual(call(process), mocked_proc.call_args)