Esempio n. 1
0
 def test_times(self):
     """ Test the update_times method. """
     from supervisor.states import ProcessStates
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     # add processes
     for info in database_copy():
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info)
         status.add_process(process)
     # get current process times
     ref_data = {process.namespec(): (process.state, info['now'], info['uptime'])
         for process in status.processes.values()
             for info in [process.infos['10.0.0.1']]}
     # update times and check
     now = int(time.time())
     status.update_times(now + 10, now)
     self.assertEqual(now + 10, status.remote_time)
     self.assertEqual(now, status.local_time)
     # test process times: only RUNNING and STOPPING have a positive uptime
     new_data = {process.namespec(): (process.state, info['now'], info['uptime'])
         for process in status.processes.values()
             for info in [process.infos['10.0.0.1']]}
     for namespec, new_info in new_data.items():
         ref_info = ref_data[namespec]
         self.assertEqual(new_info[0], ref_info[0])
         self.assertGreater(new_info[1], ref_info[1])
         if new_info[0] in [ProcessStates.RUNNING, ProcessStates.STOPPING]:
             self.assertGreater(new_info[2], ref_info[2])
         else:
             self.assertEqual(new_info[2], ref_info[2])
Esempio n. 2
0
 def test_times(self):
     """ Test the update_times method. """
     from supervisor.states import ProcessStates
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     # add processes
     for info in ProcessInfoDatabase:
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info.copy())
         status.add_process(process)
     # get current process times
     ref_data = {process.namespec(): (process.state, info['now'], info['local_time'], info.get('uptime', None))
         for process in status.processes.values() for info in [process.infos['10.0.0.1']]}
     # update times and check
     now = time.time()
     status.update_times(now + 10, now)
     self.assertEqual(now + 10, status.remote_time)
     self.assertEqual(now, status.local_time)
     # test process times: only RUNNING has an uptime
     new_data = {process.namespec(): (process.state, info['now'], info['local_time'], info.get('uptime', None))
         for process in status.processes.values() for info in [process.infos['10.0.0.1']]}
     for namespec, new_info in new_data.items():
         ref_info = ref_data[namespec]
         self.assertEqual(new_info[0], ref_info[0])
         self.assertGreater(new_info[1], ref_info[1])
         self.assertGreater(new_info[2], ref_info[2])
         if new_info[0] in [ProcessStates.RUNNING, ProcessStates.STOPPING]:
             self.assertGreater(new_info[3], ref_info[3])
         else:
             self.assertEqual(new_info[3], ref_info[3])
Esempio n. 3
0
 def test_pid_process(self):
     """ Test the pid_process method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     for info in ProcessInfoDatabase:
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info.copy())
         status.add_process(process)
     # check the namespec and pid of the running processes
     self.assertItemsEqual([('sample_test_1:xfontsel', 80879), ('sample_test_2:yeux_01', 80882)], status.pid_processes())
Esempio n. 4
0
 def test_add_process(self):
     """ Test the add_process method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     info = any_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     status.add_process(process)
     # check that process is stored
     self.assertIn(process.namespec(), status.processes.keys())
     self.assertIs(process, status.processes[process.namespec()])
Esempio n. 5
0
 def test_add_process(self):
     """ Test the add_process method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     info = any_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     status.add_process(process)
     # check that process is stored
     self.assertIn(process.namespec(), status.processes.keys())
     self.assertIs(process, status.processes[process.namespec()])
Esempio n. 6
0
 def test_pid_process(self):
     """ Test the pid_process method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     for info in database_copy():
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info)
         status.add_process(process)
     # check the namespec and pid of the running processes
     self.assertItemsEqual([('sample_test_1:xfontsel', 80879), ('sample_test_2:yeux_01', 80882)], status.pid_processes())
Esempio n. 7
0
 def test_running_process(self):
     """ Test the running_process method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     for info in ProcessInfoDatabase:
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info.copy())
         status.add_process(process)
     # check the name of the running processes
     self.assertItemsEqual(['late_segv','segv', 'xfontsel', 'yeux_01'],
         [proc.process_name for proc in status.running_processes()])
Esempio n. 8
0
 def test_running_process(self):
     """ Test the running_process method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     for info in database_copy():
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info)
         status.add_process(process)
     # check the name of the running processes
     self.assertItemsEqual(['late_segv','segv', 'xfontsel', 'yeux_01'],
         [proc.process_name for proc in status.running_processes()])
Esempio n. 9
0
 def test_loading(self):
     """ Test the loading method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     for info in ProcessInfoDatabase:
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info.copy())
         status.add_process(process)
     # check the loading of the address: gives 5 (1 per running process) by default because no rule has been loaded
     self.assertEqual(4, status.loading())
     # change expected_loading of any stopped process
     process = random.choice([proc for proc in status.processes.values() if proc.stopped()])
     process.rules.expected_loading = 50
     self.assertEqual(4, status.loading())
     # change expected_loading of any running process
     process = random.choice([proc for proc in status.processes.values() if proc.running()])
     process.rules.expected_loading = 50
     self.assertEqual(53, status.loading())
Esempio n. 10
0
 def test_loading(self):
     """ Test the loading method. """
     from supvisors.address import AddressStatus
     from supvisors.process import ProcessStatus
     status = AddressStatus('10.0.0.1', self.supvisors.logger)
     for info in database_copy():
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info)
         status.add_process(process)
     # check the loading of the address: gives 5 (1 per running process) by default because no rule has been loaded
     self.assertEqual(4, status.loading())
     # change expected_loading of any stopped process
     process = random.choice([proc for proc in status.processes.values() if proc.stopped()])
     process.rules.expected_loading = 50
     self.assertEqual(4, status.loading())
     # change expected_loading of any running process
     process = random.choice([proc for proc in status.processes.values() if proc.running()])
     process.rules.expected_loading = 50
     self.assertEqual(53, status.loading())