Test that the song cache fills up to the cache size setting
Covers a cache size above 1: songs are preloaded until the setting is reached, playing a song tops the cache up again, and the cache keeps filling after a failed download once the server answers again.
This commit is contained in:
1 parent
c1fc24adf9
commit
16724922ed
2 files changed
+52
No files matched your search
@@ -12,6 +12,7 @@ var requested_paths: Array[String] = []
|
||||
var requested_methods: Array[int] = []
|
||||
|
||||
var _responses: Dictionary = {}
|
||||
var _successes_left: Dictionary = {}
|
||||
var _previous_transport: HttpTransport
|
||||
|
||||
|
||||
@@ -39,6 +40,13 @@ func respond_json(path: String, data: Variant, response_code: int = 200) -> void
|
||||
## Answers requests to [param path] with [param body] as-is.
|
||||
func respond_bytes(path: String, body: PackedByteArray, response_code: int = 200) -> void:
|
||||
_responses[path] = {"code": response_code, "body": body}
|
||||
_successes_left.erase(path)
|
||||
|
||||
|
||||
## Lets [param successes] more requests to [param path] succeed, then answers 503 until
|
||||
## a new response is registered for the path.
|
||||
func fail_after(path: String, successes: int) -> void:
|
||||
_successes_left[path] = successes
|
||||
|
||||
|
||||
## Returns how many times [param path] has been requested.
|
||||
@@ -50,6 +58,11 @@ func request(url: String, method: int, on_complete: Callable) -> void:
|
||||
var path: String = url.trim_prefix(Settings.default_path)
|
||||
requested_paths.append(path)
|
||||
requested_methods.append(method)
|
||||
if _successes_left.has(path):
|
||||
if _successes_left[path] == 0:
|
||||
on_complete.call(503, PackedByteArray())
|
||||
return
|
||||
_successes_left[path] -= 1
|
||||
if _responses.has(path):
|
||||
on_complete.call(_responses[path].code, _responses[path].body)
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user