def test_retry_value_with_to_task(self): """Ensure that calling to_task doesn't affect the options when encoding. """ from furious.async import Async from furious.async import encode_async_options async_job = Async("something", task_args={"retry_options": {"task_retry_limit": 5}}) async_job.to_task() options = encode_async_options(async_job) self.assertEqual(5, options["task_args"]["retry_options"]["task_retry_limit"])
def test_retry_value_with_to_task(self): """Ensure that calling to_task doesn't affect the options when encoding. """ from furious. async import Async from furious. async import encode_async_options async_job = Async("something", task_args={'retry_options': { 'task_retry_limit': 5 }}) async_job.to_task() options = encode_async_options(async_job) self.assertEqual( 5, options['task_args']['retry_options']['task_retry_limit'])
def test_retry_custom(self): """Ensure that when a custom retry limit is set, that it's propagated. """ from furious.async import Async async_job = Async("something", task_args={"retry_options": {"task_retry_limit": 5}}) task = async_job.to_task() self.assertEqual(5, task.retry_options.task_retry_limit)
def test_retry_default(self): """Ensure that when no task_retry_limit specified, that the default is set. """ from furious.async import Async from furious.async import MAX_RESTARTS async_job = Async("something") task = async_job.to_task() self.assertEqual(MAX_RESTARTS, task.retry_options.task_retry_limit)
def test_retry_default(self): """Ensure that when no task_retry_limit specified, that the default is set. """ from furious. async import Async from furious. async import MAX_RESTARTS async_job = Async("something") task = async_job.to_task() self.assertEqual(MAX_RESTARTS, task.retry_options.task_retry_limit)
def test_retry_custom(self): """Ensure that when a custom retry limit is set, that it's propagated. """ from furious. async import Async async_job = Async("something", task_args={'retry_options': { 'task_retry_limit': 5 }}) task = async_job.to_task() self.assertEqual(5, task.retry_options.task_retry_limit)
def test_add_async_and_message_tasks(self, ctime): """Ensure taskqueue.Task() instances from furious Asyncs and Messages can be added. """ from google.appengine.api import taskqueue from furious. async import Async from furious.batcher import Message from furious.test_stubs.appengine.queues import add_tasks from furious.test_stubs.appengine.queues import run as run_queues # Create asyncs async = Async(target='time.ctime') async2 = Async(target='time.ctime') # Create a message options = {'task_args': {'payload': 'abcdefg'}} message = Message(payload='abc', **options) message_task = message.to_task() task_dict = { 'default': [async .to_task(), async2.to_task()], 'default-pull': [message_task] } num_added = add_tasks(self.queue_service, task_dict) # Ensure three tasks were added. self.assertEqual(3, num_added) # Run the tasks to make sure they were inserted correctly. run_queues(self.queue_service) # Ensure both push queue tasks were executed. self.assertEqual(2, ctime.call_count) # Lease the pull queue task and make sure it has the correct payload. tasks = taskqueue.Queue('default-pull').lease_tasks(3600, 100) returned_task_message = tasks[0] # Ensure pull queue task payload is the same as the original. self.assertEqual(returned_task_message.payload, message_task.payload)
def test_add_async_and_message_tasks(self, ctime): """Ensure taskqueue.Task() instances from furious Asyncs and Messages can be added. """ from google.appengine.api import taskqueue from furious.async import Async from furious.batcher import Message from furious.test_stubs.appengine.queues import add_tasks from furious.test_stubs.appengine.queues import run as run_queues # Create asyncs async = Async(target='time.ctime') async2 = Async(target='time.ctime') # Create a message options = {'task_args': {'payload': 'abcdefg'}} message = Message(payload='abc', **options) message_task = message.to_task() task_dict = {'default': [async.to_task(), async2.to_task()], 'default-pull': [message_task]} num_added = add_tasks(self.queue_service, task_dict) # Ensure three tasks were added. self.assertEqual(3, num_added) # Run the tasks to make sure they were inserted correctly. run_queues(self.queue_service) # Ensure both push queue tasks were executed. self.assertEqual(2, ctime.call_count) # Lease the pull queue task and make sure it has the correct payload. tasks = taskqueue.Queue('default-pull').lease_tasks(3600, 100) returned_task_message = tasks[0] # Ensure pull queue task payload is the same as the original. self.assertEqual(returned_task_message.payload, message_task.payload)