From 7b605d5bec0b410f430d22c73e240bf1d4dc74ae Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Tue, 9 Jul 2019 11:49:52 +0200 Subject: [PATCH] alternator-test: add test case for nested read-before-write A test for read-before-write in nested paths (inside a function call or inside a +/- operator) is added. --- alternator-test/test_update_expression.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/alternator-test/test_update_expression.py b/alternator-test/test_update_expression.py index 56fcf0714d..6ba20475c5 100644 --- a/alternator-test/test_update_expression.py +++ b/alternator-test/test_update_expression.py @@ -54,6 +54,21 @@ def test_update_expression_set_copy(test_table_s): with pytest.raises(ClientError, match='ValidationException'): test_table_s.update_item(Key={'p': p}, UpdateExpression='SET z = z') +# Test for read-before-write action where the value to be read is nested inside a - operator +def test_update_expression_set_nested_copy(test_table_s): + p = random_string() + test_table_s.update_item(Key={'p': p}, UpdateExpression='SET #n = :two', + ExpressionAttributeNames={'#n': 'n'}, ExpressionAttributeValues={':two': 2}) + test_table_s.update_item(Key={'p': p}, UpdateExpression='SET #nn = :seven - #n', + ExpressionAttributeNames={'#nn': 'nn', '#n': 'n'}, ExpressionAttributeValues={':seven': 7}) + assert test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item'] == {'p': p, 'n': 2, 'nn': 5} + + test_table_s.update_item(Key={'p': p}, UpdateExpression='SET #nnn = :nnn', + ExpressionAttributeNames={'#nnn': 'nnn'}, ExpressionAttributeValues={':nnn': [2,4]}) + test_table_s.update_item(Key={'p': p}, UpdateExpression='SET #nnnn = list_append(:val1, #nnn)', + ExpressionAttributeNames={'#nnnn': 'nnnn', '#nnn': 'nnn'}, ExpressionAttributeValues={':val1': [1,3]}) + assert test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item'] == {'p': p, 'n': 2, 'nn': 5, 'nnn': [2,4], 'nnnn': [1,3,2,4]} + # Simple test for the "REMOVE" action def test_update_expression_remove(test_table_s): p = random_string()