def test_atomic_rw(self): def evaluator(x): return x + '#1' Redis.set('dqtest-rw', 'cornell ') success, no_error = Redis.atomic_rw('dqtest-rw', evaluator) assert success and no_error assert Redis.get('dqtest-rw') == 'cornell #1' Redis.delete('dqtest-rw')
def test_atomic_rw_user_abort(self): def evaluator(x): return None Redis.set('dqtest-rw', 'meow') success, no_error = Redis.atomic_rw('dqtest-rw', evaluator) assert not success and no_error assert Redis.get('dqtest-rw') == 'meow' Redis.delete('dqtest-rw')
def test_atomic_rw_error(self): def change(): Redis.set('dqtest-rw', 'cornell') def evaluator(x): t = threading.Thread(target=change) t.start() sleep(0.5) return x + '#1' Redis.set('dqtest-rw', 'meow') success, no_error = Redis.atomic_rw('dqtest-rw', evaluator) assert not success and not no_error assert Redis.get('dqtest-rw') == 'cornell' Redis.delete('dqtest-rw')