Exemple #1
0
 def test__getattr__(self):
     task = bollard.Task.create(uuid.uuid4().hex)
     task.insert()
     async_result = bollard.AsyncResult(task)
     assert async_result.name == task['name']
     assert async_result.task_id == task['task_id']
     assert async_result.result is None
Exemple #2
0
 def test_get_timeout(self):
     task = bollard.Task.create(uuid.uuid4().hex)
     task.insert()
     async_result = bollard.AsyncResult(task)
     try:
         async_result.get(timeout=1)
     except bollard.TimeoutError:
         assert True
     else:
         assert False
Exemple #3
0
    def test_get_ready_event_failed(self):

        def foo(task):
            task['state'] = 'completed'
            task['result'] = 'Hello World!'
            task.save()

        task = bollard.Task.create(uuid.uuid4().hex)
        task.insert()
        async_result = bollard.AsyncResult(task)
        bollard.Executor.ready_events[task['task_id']] = threading.Event()

        threading.Thread(target=foo, args=(task,)).start()

        assert async_result.get() == 'Hello World!'
Exemple #4
0
    def test_get(self):

        def foo(task):
            time.sleep(2)
            task['state'] = 'completed'
            task['result'] = 'Hello World!'
            task.save()

        task = bollard.Task.create(uuid.uuid4().hex)
        task.insert()
        async_result = bollard.AsyncResult(task)

        threading.Thread(target=foo, args=(task,)).start()

        assert async_result.get() == 'Hello World!', async_result.get()
Exemple #5
0
    def test_get_failed(self):

        def foo(task):
            time.sleep(1)
            task['state'] = 'failed'
            try:
                1 / 0
            except:
                task.set_exception(sys.exc_info())
            task.save()

        task = bollard.Task.create(uuid.uuid4().hex)
        task.insert()
        async_result = bollard.AsyncResult(task)

        threading.Thread(target=foo, args=(task,)).start()

        try:
            async_result.get()
        except ZeroDivisionError:
            assert True
        else:
            assert False
Exemple #6
0
 def test__init__task_id(self):
     task = bollard.Task.create(uuid.uuid4().hex)
     task.insert()
     assert bollard.AsyncResult(task['task_id'])