Skip to content

Commit 3f3c402

Browse files
committed
Refactor progress
1 parent cab0cf3 commit 3f3c402

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

common/allocation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ def from_enc_str(
113113
fragments.append(fragment)
114114
except Exception as exc:
115115
for fragment in fragments:
116-
fragment.return_to_block()
116+
fragment.give_back()
117117
raise exc
118118
return Allocation(fragments=fragments)

common/tests/test_allocation.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)