1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 09:26:18 +00:00
supysonic/tests/base/__init__.py

35 lines
1.0 KiB
Python
Raw Normal View History

2018-03-04 20:49:56 +00:00
# coding: utf-8
2017-10-28 09:16:44 +00:00
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2017 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
2017-12-10 17:22:03 +00:00
from .test_cli import CLITestCase
Implement a cache manager for album art and transcodes Quick summary ------------- - Adds a Cache class (plus tests for it) that provides an API for managing a cache of files on disk - Adds two new settings to the configuration file: `cache_size` (default 512MB) and `transcode_cache_size` (default 1GB). - Creates two cache managers using the settings above: one for general stuff (currently album art) and one for transcodes - Adds the caching of transcoded files to disk for future use - Modifies the existing image caching to use the cache manager Longer explanations and justifications -------------------------------------- The reason I separated out transcodes into an entirely separate cache is that I could imagine a single transcode pushing out a ton of smaller images or other cached content. By separating them it should reduce the number of deletes caused by adding something to the cache. The cache manager allows for caching a value from a generator via passthrough. This means that a generator can be transparently wrapped to save its output in the cache. The bytes from the generator will be written to a temp file in the cache and yielded back. When it completes, the temp file will be renamed according to the provided cache key. This is how caching transcoded music is implemented. If multiple generators for the same key are started, they will all write to individual temp files until they complete and race to overwrite each other. Since the key should uniquely represent the content it indexes the files will be identical so overwriting them is harmless. The cache will store everything for a minimum amount of time (configurable, default is set at 5 minutes). After this time has elapsed, the data can be deleted to free up space. This minimum is so that when you cache a file to the disk you can expect it to be there after, even if another large file is added to the cache and requests that some files are deleted to make space. To ensure that a file will not be paged out of the cache regardless of the minimum time, there is a `protect` context manager that will refuse the delete the key from the cache as long as it's active. The cache has a maximum size, however this is more of a recommendation as opposed to a hard limit. The actual size will frequently exceed the limit temporarily until something can be paged out.
2019-01-14 06:46:21 +00:00
from .test_cache import CacheTestCase
2017-12-10 17:22:03 +00:00
from .test_config import ConfigTestCase
2017-10-28 09:16:44 +00:00
from .test_db import DbTestCase
2017-12-10 17:41:08 +00:00
from .test_lastfm import LastFmTestCase
2017-11-25 21:21:58 +00:00
from .test_scanner import ScannerTestCase
2018-04-01 10:32:36 +00:00
from .test_secret import SecretTestCase
2017-12-05 22:18:39 +00:00
from .test_watcher import suite as watcher_suite
2017-10-28 09:16:44 +00:00
2019-06-29 15:25:44 +00:00
2017-10-28 09:16:44 +00:00
def suite():
suite = unittest.TestSuite()
Implement a cache manager for album art and transcodes Quick summary ------------- - Adds a Cache class (plus tests for it) that provides an API for managing a cache of files on disk - Adds two new settings to the configuration file: `cache_size` (default 512MB) and `transcode_cache_size` (default 1GB). - Creates two cache managers using the settings above: one for general stuff (currently album art) and one for transcodes - Adds the caching of transcoded files to disk for future use - Modifies the existing image caching to use the cache manager Longer explanations and justifications -------------------------------------- The reason I separated out transcodes into an entirely separate cache is that I could imagine a single transcode pushing out a ton of smaller images or other cached content. By separating them it should reduce the number of deletes caused by adding something to the cache. The cache manager allows for caching a value from a generator via passthrough. This means that a generator can be transparently wrapped to save its output in the cache. The bytes from the generator will be written to a temp file in the cache and yielded back. When it completes, the temp file will be renamed according to the provided cache key. This is how caching transcoded music is implemented. If multiple generators for the same key are started, they will all write to individual temp files until they complete and race to overwrite each other. Since the key should uniquely represent the content it indexes the files will be identical so overwriting them is harmless. The cache will store everything for a minimum amount of time (configurable, default is set at 5 minutes). After this time has elapsed, the data can be deleted to free up space. This minimum is so that when you cache a file to the disk you can expect it to be there after, even if another large file is added to the cache and requests that some files are deleted to make space. To ensure that a file will not be paged out of the cache regardless of the minimum time, there is a `protect` context manager that will refuse the delete the key from the cache as long as it's active. The cache has a maximum size, however this is more of a recommendation as opposed to a hard limit. The actual size will frequently exceed the limit temporarily until something can be paged out.
2019-01-14 06:46:21 +00:00
suite.addTest(unittest.makeSuite(CacheTestCase))
2017-12-10 17:22:03 +00:00
suite.addTest(unittest.makeSuite(ConfigTestCase))
2017-10-28 09:16:44 +00:00
suite.addTest(unittest.makeSuite(DbTestCase))
2017-11-25 21:21:58 +00:00
suite.addTest(unittest.makeSuite(ScannerTestCase))
2017-12-05 22:18:39 +00:00
suite.addTest(watcher_suite())
2017-12-10 16:53:02 +00:00
suite.addTest(unittest.makeSuite(CLITestCase))
2017-12-10 17:41:08 +00:00
suite.addTest(unittest.makeSuite(LastFmTestCase))
2018-04-01 10:32:36 +00:00
suite.addTest(unittest.makeSuite(SecretTestCase))
2017-10-28 09:16:44 +00:00
return suite