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:
Sansan committed 2026-10-06 08:32:56 +02:00
1 parent c1fc24adf9
commit 16724922ed
2 files changed
+52

No files matched your search

+39
View File
@@ -119,3 +119,42 @@ func test_failed_song_info_retries_only_that_step() -> void:
assert_int(Playlist.song_object_array.size()).is_equal(songs_before + 1)
assert_str(Playlist.song_object_array.back().song_title).is_equal("Dancing Mad")
assert_bool(Playlist.is_song_downloading).is_false()
func test_preloads_as_many_songs_as_the_cache_setting() -> void:
Playlist.number_of_tracks_to_preload = 3
_runner.invoke("fetch_song")
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
assert_bool(Playlist.is_song_downloading).is_false()
func test_playing_a_song_tops_the_cache_up_again() -> void:
Playlist.number_of_tracks_to_preload = 3
_runner.invoke("fetch_song")
await _play_first_song()
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
assert_int(Playlist.song_object_array.size()).is_equal(4)
func test_cache_keeps_filling_after_a_failed_download() -> void:
_window.song_fetch_retry_seconds = 0.05
Playlist.number_of_tracks_to_preload = 3
var mp3: PackedByteArray = FileAccess.get_file_as_bytes("res://tests/data/short.mp3")
# One more download works, then the server stops answering
_server.fail_after("/music/rand", 1)
_runner.invoke("fetch_song")
await await_millis(150)
assert_int(Playlist.get_preloaded_songs()).is_equal(2)
assert_bool(Playlist.is_song_downloading).is_true()
_server.respond_bytes("/music/rand", mp3)
await await_millis(150)
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
assert_bool(Playlist.is_song_downloading).is_false()