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
c985a6ce5b
commit
f67dccbf52
4 files changed
+167
-65
No files matched your search
@@ -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