lbry-sdk/tests/unit/blob/test_disk_space_manager.py

31 lines
1 KiB
Python
Raw Normal View History

2021-08-06 16:44:57 +02:00
import os
import unittest
import tempfile
import lbry.wallet
from lbry.conf import Config
from lbry.blob.disk_space_manager import DiskSpaceManager
class ConfigurationTests(unittest.TestCase):
2021-08-16 20:15:12 +02:00
def test_space_management(self):
2021-08-06 16:44:57 +02:00
with tempfile.TemporaryDirectory() as temp_dir:
2021-08-06 16:52:47 +02:00
os.mkdir(os.path.join(temp_dir, 'blobfiles'))
2021-08-06 16:44:57 +02:00
config = Config(
2021-08-16 20:15:12 +02:00
blob_storage_limit=5,
2021-08-06 16:44:57 +02:00
data_dir=temp_dir,
wallet_dir=temp_dir,
2021-08-16 20:15:12 +02:00
config=os.path.join(temp_dir, 'settings.yml'),
2021-08-06 16:44:57 +02:00
)
dsm = DiskSpaceManager(config)
self.assertEqual(0, dsm.space_used_mb)
2021-08-16 20:15:12 +02:00
for file_no in range(10):
with open(os.path.join(config.data_dir, 'blobfiles', f'3mb-{file_no}'), 'w') as blob:
blob.write('0' * 1 * 1024 * 1024)
self.assertEqual(10, dsm.space_used_mb)
self.assertTrue(dsm.clean())
2021-08-16 20:54:17 +02:00
self.assertEqual(5, dsm.space_used_mb)
self.assertFalse(dsm.clean())
2021-08-16 20:15:12 +02:00