def test_get_workers_many_workers(self): num_of_workers = MANY test_workers = [] for job in range(num_of_workers): # Create workers and add them to a list for bookkeeping test_workers.append(api.create_worker()) workers_list = api.get_workers() # Verify that the workers list contains the correct number of workers self.assertEqual(len(workers_list), num_of_workers) check_worker_fields(self, workers_list, test_workers)
def test_get_workers_one_worker(self): num_of_workers = ONE test_workers = [] # Create one worker and add them to a list for bookkeeping test_workers.append(api.create_worker()) workers_list = api.get_workers() # Verify that the workers list contains exactly one worker self.assertEqual(len(workers_list), num_of_workers) # Verify that the information we get is the same as what was set check_worker_fields(self, workers_list, test_workers)
def test_get_next_worker_one_worker_many_requests(self): num_of_workers = ONE num_of_requests = MANY test_workers = [] # Create one worker and it to a list for bookkeeping test_workers.append(api.create_worker()) # Verify that the test workers contains exactly one worker self.assertEqual(len(test_workers), num_of_workers) workers_list = [] for request in range(num_of_requests): # Get workers and add them to a list for # comparison with list of test workers workers_list.append(api.get_next_worker()) # Verify that the workers list contains # as many workers as there were requests self.assertEqual(len(workers_list), num_of_requests) # Verify that the information we get is the same as what was set check_worker_fields(self, workers_list, test_workers)
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)
def test_get_next_worker_many_workers_more_requests(self): num_of_workers = MANY num_of_requests = MORE_THAN_MANY 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()) # Verify that the test workers contains # the correct number of workers self.assertEqual(len(test_workers), num_of_workers) workers_list = [] for request in range(num_of_requests): # Get more workers than available in the test workers # (popped workers are pushed to the end of the queue) # and add them to a list for comparison workers_list.append(api.get_next_worker()) # Verify that the workers list contains # as many workers as there were requests self.assertEqual(len(workers_list), num_of_requests) # Verify that the information we get is the same as what was set check_worker_fields(self, workers_list, test_workers)
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)
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)