@@ -198,10 +198,10 @@ def test_from_enc_str_bad_no_fragments():
198198 _allocation = Allocation .from_enc_str ("" , pool )
199199
200200
201- def test_from_enc_str_bad_fragment ():
201+ def test_from_enc_str_bad_one_fragment ():
202202 """
203- Attempt to create an Allocation from a bad APIAllocation: one of the fragments has an invalid
204- block UUID.
203+ Attempt to create an Allocation from a bad encoded string (only one fragment in the string,
204+ which is bad)
205205 """
206206 # pylint: disable=protected-access
207207 pool , blocks = create_test_pool_and_blocks ([10 ])
@@ -217,3 +217,20 @@ def test_from_enc_str_bad_fragment():
217217 # No data taken from pool
218218 assert pool .nr_used_bytes == 0
219219 assert blocks [0 ]._data == bytes .fromhex ("00010203040506070809" )
220+
221+
222+ def test_from_enc_str_bad_two_fragment ():
223+ """
224+ Attempt to create an Allocation from a bad encoded string. There are two fragments in the
225+ encoded string; the second is bad. Make sure the first one is give back to the pool.
226+ """
227+ # pylint: disable=protected-access
228+ pool , blocks = create_test_pool_and_blocks ([10 , 5 ])
229+ fragment_1_enc_str = f"{ blocks [0 ].uuid } :0:5"
230+ fragment_2_enc_str = "not-a-uuid:0:5"
231+ allocation_enc_str = f"{ fragment_1_enc_str } ,{ fragment_2_enc_str } "
232+ with pytest .raises (InvalidBlockUUIDError ):
233+ _allocation = Allocation .from_enc_str (allocation_enc_str , pool )
234+ assert pool .nr_used_bytes == 0
235+ assert blocks [0 ]._data == bytes .fromhex ("00010203040506070809" )
236+ assert blocks [1 ]._data == bytes .fromhex ("0001020304" )
0 commit comments