@@ -770,6 +770,54 @@ def lambda_handler(event, context):
770
770
stubber .deactivate ()
771
771
772
772
773
+ @pytest .mark .parametrize ("idempotency_config" , [{"use_local_cache" : False }, {"use_local_cache" : True }], indirect = True )
774
+ def test_idempotent_lambda_expires_in_progress_before_expire_with_sort_key (
775
+ idempotency_config : IdempotencyConfig ,
776
+ persistence_store_compound_static_pk_value : DynamoDBPersistenceLayer ,
777
+ lambda_apigw_event ,
778
+ timestamp_future ,
779
+ lambda_response ,
780
+ hashed_idempotency_key ,
781
+ lambda_context ,
782
+ ):
783
+ stubber = stub .Stubber (persistence_store_compound_static_pk_value .client )
784
+
785
+ stubber .add_client_error ("put_item" , "ConditionalCheckFailedException" )
786
+
787
+ now = datetime .datetime .now ()
788
+ period = datetime .timedelta (seconds = 5 )
789
+ timestamp_expires_in_progress = int ((now + period ).timestamp () * 1000 )
790
+
791
+ expected_params_get_item = {
792
+ "TableName" : TABLE_NAME ,
793
+ "Key" : {"id" : {"S" : "static-value" }, "sk" : {"S" : hashed_idempotency_key }},
794
+ "ConsistentRead" : True ,
795
+ }
796
+ ddb_response_get_item = {
797
+ "Item" : {
798
+ "id" : {"S" : "static-value" },
799
+ "expiration" : {"N" : timestamp_future },
800
+ "in_progress_expiration" : {"N" : str (timestamp_expires_in_progress )},
801
+ "data" : {"S" : '{"message": "test", "statusCode": 200' },
802
+ "status" : {"S" : "INPROGRESS" },
803
+ "sk" : {"S" : hashed_idempotency_key },
804
+ },
805
+ }
806
+ stubber .add_response ("get_item" , ddb_response_get_item , expected_params_get_item )
807
+
808
+ stubber .activate ()
809
+
810
+ @idempotent (config = idempotency_config , persistence_store = persistence_store_compound_static_pk_value )
811
+ def lambda_handler (event , context ):
812
+ return lambda_response
813
+
814
+ with pytest .raises (IdempotencyAlreadyInProgressError , match = "and sort key" ):
815
+ lambda_handler (lambda_apigw_event , lambda_context )
816
+
817
+ stubber .assert_no_pending_responses ()
818
+ stubber .deactivate ()
819
+
820
+
773
821
@pytest .mark .parametrize ("idempotency_config" , [{"use_local_cache" : False }, {"use_local_cache" : True }], indirect = True )
774
822
def test_idempotent_lambda_expires_in_progress_after_expire (
775
823
idempotency_config : IdempotencyConfig ,
0 commit comments