@@ -963,7 +963,7 @@ def test_data_queued_in_order(self):
963
963
writes = self .q .request_writes (offset = 11 , data = 'hello again' )
964
964
self .assertEqual (writes , [{'offset' : 11 , 'data' : 'hello again' }])
965
965
966
- def test_writes_below_min_offset_are_ignored (self ):
966
+ def test_writes_with_last_byte_below_min_offset_are_ignored (self ):
967
967
self .q .request_writes (offset = 0 , data = 'a' )
968
968
self .q .request_writes (offset = 1 , data = 'b' )
969
969
self .q .request_writes (offset = 2 , data = 'c' )
@@ -978,13 +978,36 @@ def test_writes_below_min_offset_are_ignored(self):
978
978
[{'offset' : 3 , 'data' : 'd' }],
979
979
)
980
980
981
- def test_duplicate_writes_are_ignored (self ):
981
+ def test_writes_below_min_offset_with_last_byte_above_min_offset_are_queued (
982
+ self ,
983
+ ):
984
+ self .assertEqual (
985
+ self .q .request_writes (offset = 0 , data = 'foo' ),
986
+ [{'offset' : 0 , 'data' : 'foo' }],
987
+ )
988
+
989
+ # Even though a partial write of 'foo' was completed at offset 0,
990
+ # a subsequent request to the same offset with a longer
991
+ # length will write a substring of the data starting at
992
+ # index next_offset.
993
+ self .assertEqual (
994
+ self .q .request_writes (offset = 0 , data = 'foo bar' ),
995
+ [
996
+ # Note we are writing a substring of the data starting at
997
+ # index 3 since the previous write to index 0 had length 3.
998
+ {'offset' : 3 , 'data' : ' bar' },
999
+ ],
1000
+ )
1001
+
1002
+ def test_duplicate_writes_same_length_are_ignored (self ):
982
1003
self .q .request_writes (offset = 2 , data = 'c' )
983
1004
self .q .request_writes (offset = 1 , data = 'b' )
984
1005
985
1006
# We're still waiting for offset=0, but if
986
- # a duplicate write comes in for offset=2/offset=1
987
- # it's ignored. This gives "first one wins" behavior.
1007
+ # a duplicate write with the same length comes in
1008
+ # for offset=2/offset=1 it's ignored.
1009
+ # This gives "largest one wins" behavior with ties
1010
+ # broken via "first one wins".
988
1011
self .assertEqual (self .q .request_writes (offset = 2 , data = 'X' ), [])
989
1012
self .assertEqual (self .q .request_writes (offset = 1 , data = 'Y' ), [])
990
1013
@@ -997,3 +1020,22 @@ def test_duplicate_writes_are_ignored(self):
997
1020
{'offset' : 2 , 'data' : 'c' },
998
1021
],
999
1022
)
1023
+
1024
+ def test_duplicate_writes_longer_length_update_queue (self ):
1025
+ self .q .request_writes (offset = 1 , data = 'b' )
1026
+
1027
+ # We're still waiting for offset=0, but if
1028
+ # a write comes in for the same offset=2/offset=1
1029
+ # it updates the queue if the request contains more data.
1030
+ # This gives "largest one wins" behavior with ties
1031
+ # broken via "first one wins".
1032
+ self .assertEqual (self .q .request_writes (offset = 1 , data = 'bar' ), [])
1033
+
1034
+ self .assertEqual (
1035
+ self .q .request_writes (offset = 0 , data = 'a' ),
1036
+ [
1037
+ {'offset' : 0 , 'data' : 'a' },
1038
+ # Note we're seeing 'bar', and not 'b', since len(bar) > len(b).
1039
+ {'offset' : 1 , 'data' : 'bar' },
1040
+ ],
1041
+ )
0 commit comments