示例#1
0
 def test_update_heartbeat_deleted_worker(self):
     test_workers = []
     # Create a temporary worker in the test workers
     to_be_deleted = test_workers.append(api.create_worker())
     # Destroy the only worker in the list
     api.destroy_worker(api.get_next_worker())
     # Verify that we do not update nonexistent workers
     with self.assertRaises(ValueError):
         api.update_heartbeat(to_be_deleted)
示例#2
0
 def test_update_heartbeat_deleted_worker(self):
     test_workers = []
     # Create a temporary worker in the test workers
     to_be_deleted = test_workers.append(api.create_worker())
     # Destroy the only worker in the list
     api.destroy_worker(api.get_next_worker())
     # Verify that we do not update nonexistent workers
     with self.assertRaises(ValueError):
         api.update_heartbeat(to_be_deleted)
示例#3
0
def check_worker_heartbeat(events):
    for w in api.get_workers():
        if (datetime.now() - w.heartbeat) > WORKER_HEARTBEAT_TIMEOUT:
            for schedule in api.get_schedules(w):
                schedule.worker = api.get_next_worker()

            api.destroy_worker(w)

    delay = WORKER_HEARTBEAT_TIMEOUT.total_seconds()
    events.enter(delay, 1, check_worker_heartbeat, (events,))
示例#4
0
 def test_destroy_worker_one_worker(self):
     test_workers = []
     # Create one worker and add it to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Kill the only worker in the list
     api.destroy_worker(test_workers[0])
     # Try to get a worker from an empty pool
     next_worker = api.get_next_worker()
     # Verify that the next worker does not exist
     self.assertEqual(next_worker, None)
示例#5
0
 def test_destroy_worker_one_worker(self):
     test_workers = []
     # Create one worker and add it to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Kill the only worker in the list
     api.destroy_worker(test_workers[0])
     # Try to get a worker from an empty pool
     next_worker = api.get_next_worker()
     # Verify that the next worker does not exist
     self.assertEqual(next_worker, None)
示例#6
0
def check_worker_heartbeat(events):
    for w in api.get_workers():
        if (datetime.now() - w.heartbeat) > WORKER_HEARTBEAT_TIMEOUT:
            for schedule in api.get_schedules(w):
                schedule.worker = api.get_next_worker()

            api.destroy_worker(w)

    delay = WORKER_HEARTBEAT_TIMEOUT.total_seconds()
    events.enter(delay, 1, check_worker_heartbeat, (events, ))
示例#7
0
 def test_destroy_worker_many_workers_random_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Leave one worker remaining for comparison at the end
     num_of_requests = num_of_workers - 1
     # Automatic flooring care of Python
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill number of requests random worker in the list
     for request in range(num_of_requests):
         random_worker = random.randrange(len(test_workers))
         api.destroy_worker(test_workers.pop(random_worker))
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the workers list contains exactly one worker
     self.assertEqual(len(workers_list), 1)
     # Verify that the correct remaining worker is still in the list
     check_worker_fields(self, workers_list, test_workers)
示例#8
0
 def test_destroy_worker_many_workers_random_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Leave one worker remaining for comparison at the end
     num_of_requests = num_of_workers - 1
     # Automatic flooring care of Python
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill number of requests random worker in the list
     for request in range(num_of_requests):
         random_worker = random.randrange(len(test_workers))
         api.destroy_worker(test_workers.pop(random_worker))
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the workers list contains exactly one worker
     self.assertEqual(len(workers_list), 1)
     # Verify that the correct remaining worker is still in the list
     check_worker_fields(self, workers_list, test_workers)
示例#9
0
 def test_destroy_worker_many_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Automatic flooring care of Python
     num_of_requests = num_of_workers/2
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill the floor of half of the workers in the list
     for request in range(num_of_requests):
         api.destroy_worker(test_workers.pop())
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the correct workers are still in the list
     check_worker_fields(self, workers_list, test_workers)
     # Remove the rest of the test workers
     while test_workers:
         api.destroy_worker(test_workers.pop())
     # Try to get a worker from an empty pool
     next_worker = api.get_next_worker()
     # Verify that the next worker does not exist
     self.assertEqual(next_worker, None)
示例#10
0
 def test_destroy_worker_many_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Automatic flooring care of Python
     num_of_requests = num_of_workers / 2
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill the floor of half of the workers in the list
     for request in range(num_of_requests):
         api.destroy_worker(test_workers.pop())
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the correct workers are still in the list
     check_worker_fields(self, workers_list, test_workers)
     # Remove the rest of the test workers
     while test_workers:
         api.destroy_worker(test_workers.pop())
     # Try to get a worker from an empty pool
     next_worker = api.get_next_worker()
     # Verify that the next worker does not exist
     self.assertEqual(next_worker, None)
示例#11
0
文件: worker.py 项目: BigFav/MegaCron
def cleanup():
    global worker
    api.destroy_worker(worker)
示例#12
0
 def test_remove_schedule_empty_schedules(self):
     test_schedules = []
     # Verify that we do not destroy nonexistent workers
     with self.assertRaises(ValueError):
         api.destroy_worker(test_schedules)
示例#13
0
 def test_destroy_worker_empty_workers(self):
     test_workers = []
     # Verify that we do not destroy nonexistent workers
     with self.assertRaises(ValueError):
         api.destroy_worker(test_workers)
示例#14
0
 def test_remove_schedule_empty_schedules(self):
     test_schedules = []
     # Verify that we do not destroy nonexistent workers
     with self.assertRaises(ValueError):
         api.destroy_worker(test_schedules)
示例#15
0
 def test_destroy_worker_empty_workers(self):
     test_workers = []
     # Verify that we do not destroy nonexistent workers
     with self.assertRaises(ValueError):
         api.destroy_worker(test_workers)
示例#16
0
def cleanup():
    global worker
    api.destroy_worker(worker)