@@ -100,7 +100,7 @@ def test_get_block_unknown_uuid():
100100 pool .get_block (uuid )
101101
102102
103- def test_allocate_success_empty_pool_first_block ():
103+ def test_allocate_success_empty_pool_first_block_full ():
104104 """
105105 Allocate an allocation from a pool. The pool is empty. The allocation fits in the first block.
106106 """
@@ -111,7 +111,7 @@ def test_allocate_success_empty_pool_first_block():
111111 assert pool .nr_used_bytes == 10
112112
113113
114- def test_allocate_success_empty_pool_two_blocks ():
114+ def test_allocate_success_empty_pool_first_block_full_second_block_partial ():
115115 """
116116 Allocate an allocation from a pool. The pool is empty. The allocation is spread over two blocks.
117117 """
@@ -122,6 +122,20 @@ def test_allocate_success_empty_pool_two_blocks():
122122 assert pool .nr_used_bytes == 8
123123
124124
125+ def test_allocate_success_empty_pool_first_block_full_second_block_full ():
126+ """
127+ Allocate an allocation from a pool. The pool is empty. The allocation is spread over two blocks.
128+ """
129+ pool , _blocks = _create_test_pool_and_block ([5 , 4 ])
130+ allocation = pool .allocate (9 , purpose = "test" )
131+ assert allocation is not None
132+ assert allocation .data == bytes .fromhex ("000102030400010203" )
133+ assert pool .nr_used_bytes == 9
134+
135+
136+ # TODO: Also test re-allocation after giving back
137+
138+
125139def test_allocate_failure_insufficient_space ():
126140 """
127141 Attempt to allocate an allocation from a pool. There is not enough unused data in the pool.
@@ -130,3 +144,17 @@ def test_allocate_failure_insufficient_space():
130144 with pytest .raises (OutOfPreSharedRandomDataError ):
131145 pool .allocate (20 , purpose = "test" )
132146 assert pool .nr_used_bytes == 0
147+
148+
149+ def test_delete_fully_used_blocks ():
150+ """
151+ Delete fully used PSRD blocks from the pool.
152+ """
153+ pool , _blocks = _create_test_pool_and_block ([10 , 11 ])
154+ # Allocate all of the first block and part of the second block.
155+ _allocation = pool .allocate (15 , purpose = "test1" )
156+ assert pool .nr_used_bytes == 15
157+ assert pool .nr_unused_bytes == 6
158+ pool .delete_fully_used_blocks ()
159+ assert pool .nr_used_bytes == 5
160+ assert pool .nr_unused_bytes == 6
0 commit comments