Пример #1
0
def test_raise_error_if_acquired():
    uid = '11'
    Lock._acquire(uid, '12', 'a')
    clear_cache()
    with pytest.raises(RuntimeError):
        with Lock(uid, '13'):
            assert True
Пример #2
0
def test_raise_error_if_acquired():
    uid = '11'
    Lock._acquire(uid, '12', 'a')
    clear_cache()
    with pytest.raises(RuntimeError):
        with Lock(uid, '13'):
            assert True
Пример #3
0
def test_lock_released_exception():
    uid = '11'
    with pytest.raises(Exception):
        with Lock(uid, uid):
            raise Exception

    new_lock = Lock._acquire(uid, '12', 'a')
    assert new_lock.who_is_locking() == '12'
Пример #4
0
def test_time_sleep_called(msleep):
    uid = '11'
    Lock._acquire(uid, '12', 'a')
    clear_cache()
    sleep_time = 5
    with pytest.raises(RuntimeError):
        with Lock(uid, '13', 1, sleep_time):
            assert True
    msleep.assert_called_once_with(sleep_time)
Пример #5
0
def test_acquire_release_logic():
    uid = '2131'
    first = '1111'
    second = '2222'
    assert Lock._acquire(uid, first, 'a').who_is_locking() == first
    clear_cache()
    assert Lock._acquire(uid, second, 'a').who_is_locking() == first
    Lock._release(uid, first, 'a')
    assert Lock._acquire(uid, second, 'a').who_is_locking() == second
Пример #6
0
def test_time_sleep_called(msleep):
    uid = '11'
    Lock._acquire(uid, '12', 'a')
    clear_cache()
    sleep_time = 5
    with pytest.raises(RuntimeError):
        with Lock(uid, '13', 1, waiter=Waiter(sleep_time)):
            assert True
    msleep.assert_called_once_with(uid, '13')
Пример #7
0
def test_acquire_release_logic():
    uid = '2131'
    first = '1111'
    second = '2222'
    assert Lock._acquire(uid, first, 'a').who_is_locking() == first
    clear_cache()
    assert Lock._acquire(uid, second, 'a').who_is_locking() == first
    Lock._release(uid, first, 'a')
    assert Lock._acquire(uid, second, 'a').who_is_locking() == second
Пример #8
0
def test_lock_released_exception():
    uid = '11'
    with pytest.raises(Exception):
        with Lock(uid, uid):
            raise Exception

    new_lock = Lock._acquire(uid, '12', 'a')
    assert new_lock.who_is_locking() == '12'
Пример #9
0
 def soft_stop(self, ctxt, plan_uid):
     with Lock(plan_uid,
               str(get_current_ident()),
               retries=20,
               waiter=Waiter(1)):
         plan = graph.get_graph(plan_uid)
         for n in plan:
             if plan.node[n]['status'] in (states.PENDING.name,
                                           states.ERROR_RETRY.name):
                 plan.node[n]['status'] = states.SKIPPED.name
         graph.update_graph(plan)
Пример #10
0
 def next(self, ctxt, plan_uid):
     with Lock(plan_uid,
               str(get_current_ident()),
               retries=20,
               waiter=Waiter(1)):
         log.debug('Received *next* event for %s', plan_uid)
         plan = graph.get_graph(plan_uid)
         if len(plan) == 0:
             raise ValueError('Plan {} is empty'.format(plan_uid))
         rst = self._next(plan)
         for task_name in rst:
             self._do_scheduling(plan, task_name)
         graph.update_graph(plan)
         log.debug('Scheduled tasks %r', rst)
         # process tasks with tasks client
         return rst
Пример #11
0
 def update_next(self, ctxt, status, errmsg):
     log.debug('Received update for TASK %s - %s %s', ctxt['task_id'],
               status, errmsg)
     plan_uid, task_name = ctxt['task_id'].rsplit(':', 1)
     with Lock(plan_uid,
               str(get_current_ident()),
               retries=20,
               waiter=Waiter(1)):
         plan = graph.get_graph(plan_uid)
         self._do_update(plan, task_name, status, errmsg=errmsg)
         rst = self._next(plan)
         for task_name in rst:
             self._do_scheduling(plan, task_name)
         graph.update_graph(plan)
         log.debug('Scheduled tasks %r', rst)
         return rst
Пример #12
0
def test_lock_acquired_released():
    uid = '11'
    with Lock(uid, uid):
        clear_cache()
        assert Lock._acquire(uid, '12', 'a').who_is_locking() == '11'
    assert Lock._acquire(uid, '12', 'a').who_is_locking() == '12'
Пример #13
0
def test_lock_acquired_released():
    uid = '11'
    with Lock(uid, uid, waiter=Waiter(1)):
        clear_cache()
        assert Lock._acquire(uid, '12', 'a').who_is_locking() == '11'
    assert Lock._acquire(uid, '12', 'a').who_is_locking() == '12'