Retry failed song downloads instead of getting stuck
MusicServerClient functions now take an optional on_failed callback, called when a request fails or returns invalid JSON. Before, a failed request was silently dropped, so a failure while preloading a song left Playlist.is_song_downloading set forever and no more songs were fetched. Song fetching retries the step that failed (download, queue or info) every song_fetch_retry_seconds, so the server and the game keep the same playlist.
This commit is contained in:
1 parent
91adf52cf4
commit
40ed4da908
4 files changed
+167
-65
No files matched your search
@@ -78,3 +78,44 @@ func test_cannot_add_player_without_name() -> void:
|
||||
_add_player("")
|
||||
|
||||
assert_array(Settings.player_array).is_empty()
|
||||
|
||||
|
||||
func test_failed_song_download_is_retried_until_the_server_answers() -> void:
|
||||
_window.song_fetch_retry_seconds = 0.05
|
||||
var songs_before: int = Playlist.song_object_array.size()
|
||||
var mp3: PackedByteArray = FileAccess.get_file_as_bytes("res://tests/data/short.mp3")
|
||||
_server.respond_bytes("/music/rand", PackedByteArray(), 503)
|
||||
var rand_requests_before: int = _server.count("/music/rand")
|
||||
|
||||
_runner.invoke("fetch_song")
|
||||
await await_millis(200)
|
||||
|
||||
assert_int(_server.count("/music/rand") - rand_requests_before).is_greater(1)
|
||||
assert_int(Playlist.song_object_array.size()).is_equal(songs_before)
|
||||
assert_bool(Playlist.is_song_downloading).is_true()
|
||||
|
||||
_server.respond_bytes("/music/rand", mp3)
|
||||
await await_millis(200)
|
||||
|
||||
assert_int(Playlist.song_object_array.size()).is_equal(songs_before + 1)
|
||||
assert_bool(Playlist.is_song_downloading).is_false()
|
||||
|
||||
|
||||
func test_failed_song_info_retries_only_that_step() -> void:
|
||||
_window.song_fetch_retry_seconds = 0.05
|
||||
var songs_before: int = Playlist.song_object_array.size()
|
||||
_server.respond_bytes("/music/info", PackedByteArray(), 503)
|
||||
var rand_before: int = _server.count("/music/rand")
|
||||
var queue_before: int = _server.count("/music/addQue")
|
||||
|
||||
_runner.invoke("fetch_song")
|
||||
await await_millis(200)
|
||||
_next_song_is(SONG_INFO[1])
|
||||
await await_millis(200)
|
||||
|
||||
# The song was downloaded and queued once; only the info request was repeated
|
||||
assert_int(_server.count("/music/rand") - rand_before).is_equal(1)
|
||||
assert_int(_server.count("/music/addQue") - queue_before).is_equal(1)
|
||||
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()
|
||||
@@ -63,6 +63,39 @@ func test_invalid_json_does_not_call_back() -> void:
|
||||
assert_bool(called[0]).is_false()
|
||||
|
||||
|
||||
func test_failed_request_calls_on_failed() -> void:
|
||||
_server.respond_bytes("/music/rand", PackedByteArray(), 503)
|
||||
var outcome: Array[String] = []
|
||||
|
||||
MusicServerClient.fetch_random_song(false,
|
||||
func(_body: PackedByteArray) -> void: outcome.append("done"),
|
||||
func() -> void: outcome.append("failed"))
|
||||
|
||||
assert_array(outcome).contains_exactly(["failed"])
|
||||
|
||||
|
||||
func test_invalid_json_calls_on_failed() -> void:
|
||||
_server.respond_bytes("/music/info", "not json".to_utf8_buffer())
|
||||
var outcome: Array[String] = []
|
||||
|
||||
MusicServerClient.fetch_song_info(
|
||||
func(_data: Variant) -> void: outcome.append("done"),
|
||||
func() -> void: outcome.append("failed"))
|
||||
|
||||
assert_array(outcome).contains_exactly(["failed"])
|
||||
|
||||
|
||||
func test_successful_request_does_not_call_on_failed() -> void:
|
||||
_server.respond_bytes("/music/addQue", PackedByteArray())
|
||||
var outcome: Array[String] = []
|
||||
|
||||
MusicServerClient.add_to_queue(
|
||||
func() -> void: outcome.append("done"),
|
||||
func() -> void: outcome.append("failed"))
|
||||
|
||||
assert_array(outcome).contains_exactly(["done"])
|
||||
|
||||
|
||||
func test_send_calls_back_without_arguments() -> void:
|
||||
_server.respond_bytes("/music/reset", PackedByteArray())
|
||||
var called: Array[bool] = [false]
|
||||
|
||||
Reference in new issue
Block a user