Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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,))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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, ))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 11
0
def cleanup():
    global worker
    api.destroy_worker(worker)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 16
0
def cleanup():
    global worker
    api.destroy_worker(worker)