def test_doing_work_with_two_workers_and_generator(self): config = DotDict() config.logger = self.logger config.number_of_threads = 2 config.maximum_queue_size = 2 my_list = [] def insert_into_list(anItem): my_list.append(anItem) ttm = ThreadedTaskManager(config, task_func=insert_into_list, job_source_iterator=(((x,), {}) for x in xrange(10)) ) try: ttm.start() time.sleep(0.2) ok_(len(ttm.thread_list) == 2, "expected 2 threads, but found %d" % len(ttm.thread_list)) ok_(len(my_list) == 10, 'expected to do 10 inserts, ' 'but %d were done instead' % len(my_list)) ok_(sorted(my_list) == range(10), 'expected %s, but got %s' % (range(10), sorted(my_list))) except Exception: # we got threads to join ttm.wait_for_completion() raise
def test_doing_work_with_two_workers_and_generator(self): config = DotDict() config.logger = self.logger config.number_of_threads = 2 config.maximum_queue_size = 2 my_list = [] def insert_into_list(anItem): my_list.append(anItem) ttm = ThreadedTaskManager(config, task_func=insert_into_list, job_source_iterator=(((x,), {}) for x in xrange(10)) ) try: ttm.start() time.sleep(0.2) assert len(ttm.thread_list) == 2 assert len(my_list) == 10 assert sorted(my_list) == list(range(10)) except Exception: # we got threads to join ttm.wait_for_completion() raise
def test_constuctor1(self): config = DotDict() config.number_of_threads = 1 config.maximum_queue_size = 1 ttm = ThreadedTaskManager(config) try: assert ttm.config == config assert ttm.task_func == default_task_func assert not ttm.quit finally: # we got threads to join ttm._kill_worker_threads()
def test_constuctor1(self): config = DotDict() config.logger = self.logger config.number_of_threads = 1 config.maximum_queue_size = 1 ttm = ThreadedTaskManager(config) try: ok_(ttm.config == config) ok_(ttm.logger == self.logger) ok_(ttm.task_func == default_task_func) ok_(ttm.quit == False) finally: # we got threads to join ttm._kill_worker_threads()
def test_doing_work_with_one_worker(self): config = DotDict() config.logger = self.logger config.number_of_threads = 1 config.maximum_queue_size = 1 my_list = [] def insert_into_list(anItem): my_list.append(anItem) ttm = ThreadedTaskManager(config, task_func=insert_into_list ) try: ttm.start() time.sleep(0.2) ok_(len(my_list) == 10, 'expected to do 10 inserts, ' 'but %d were done instead' % len(my_list)) ok_(my_list == range(10), 'expected %s, but got %s' % (range(10), my_list)) ttm.stop() except Exception: # we got threads to join ttm.wait_for_completion() raise
def test_blocking_start_with_quit_on_empty(self): config = DotDict() config.number_of_threads = 2 config.maximum_queue_size = 2 config.quit_on_empty_queue = True calls = [] def task_func(index): calls.append(index) tm = ThreadedTaskManager(config, task_func=task_func) waiting_func = Mock() tm.blocking_start(waiting_func=waiting_func) assert len(calls) == 10
def test_blocking_start_with_quit_on_empty(self): config = DotDict() config.logger = self.logger config.number_of_threads = 2 config.maximum_queue_size = 2 config.quit_on_empty_queue = True tm = ThreadedTaskManager( config, task_func=Mock() ) waiting_func = Mock() tm.blocking_start(waiting_func=waiting_func) eq_( tm.task_func.call_count, 10 )
def test_start1(self): config = DotDict() config.number_of_threads = 1 config.maximum_queue_size = 1 ttm = ThreadedTaskManager(config) try: ttm.start() time.sleep(0.2) assert ttm.queuing_thread.isAlive(), "the queing thread is not running" assert len(ttm.thread_list) == 1, "where's the worker thread?" assert ttm.thread_list[0].isAlive(), "the worker thread is stillborn" ttm.stop() assert not ttm.queuing_thread.isAlive(), "the queuing thread did not stop" except Exception: # we got threads to join ttm.wait_for_completion()
def test_doing_work_with_one_worker(self): config = DotDict() config.number_of_threads = 1 config.maximum_queue_size = 1 my_list = [] def insert_into_list(anItem): my_list.append(anItem) ttm = ThreadedTaskManager(config, task_func=insert_into_list) try: ttm.start() time.sleep(0.2) assert len(my_list) == 10 assert my_list == list(range(10)) ttm.stop() except Exception: # we got threads to join ttm.wait_for_completion() raise
def test_doing_work_with_two_workers_and_generator(self): config = DotDict() config.number_of_threads = 2 config.maximum_queue_size = 2 my_list = [] def insert_into_list(anItem): my_list.append(anItem) ttm = ThreadedTaskManager( config, task_func=insert_into_list, job_source_iterator=(((x, ), {}) for x in range(10)), ) try: ttm.start() time.sleep(0.2) assert len(ttm.thread_list) == 2 assert len(my_list) == 10 assert sorted(my_list) == list(range(10)) except Exception: # we got threads to join ttm.wait_for_completion() raise