Make question loading resilient to network failures
This commit is contained in:
@@ -11,6 +11,8 @@ func _initialize() -> void:
|
||||
_test_eliminated_choice_uses_rich_text_strikeout()
|
||||
_test_explanation_highlighting_has_no_status_heading()
|
||||
_test_collapsed_followup_review_expands()
|
||||
_test_question_failure_retry_classification()
|
||||
_test_transient_question_failure_keeps_player_waiting()
|
||||
quit(1 if failures > 0 else 0)
|
||||
|
||||
|
||||
@@ -141,6 +143,32 @@ func _test_collapsed_followup_review_expands() -> void:
|
||||
player.free()
|
||||
|
||||
|
||||
func _test_question_failure_retry_classification() -> void:
|
||||
var service = load("res://scripts/autoload/question_bank_service.gd").new()
|
||||
_assert(service._is_transient_question_failure(HTTPRequest.RESULT_CANT_CONNECT, 0), "connection failures should retry")
|
||||
_assert(service._is_transient_question_failure(HTTPRequest.RESULT_SUCCESS, 429), "rate limits should retry")
|
||||
_assert(service._is_transient_question_failure(HTTPRequest.RESULT_SUCCESS, 503), "server failures should retry")
|
||||
_assert(not service._is_transient_question_failure(HTTPRequest.RESULT_SUCCESS, 400), "invalid requests should not retry")
|
||||
_assert(not service._is_transient_question_failure(HTTPRequest.RESULT_SUCCESS, 401), "authentication failures should not retry")
|
||||
service.free()
|
||||
|
||||
|
||||
func _test_transient_question_failure_keeps_player_waiting() -> void:
|
||||
var question_bank = root.get_node("QuestionBankService")
|
||||
var prior_state: String = question_bank.load_state
|
||||
var player = load("res://scripts/ui/question_player.gd").new()
|
||||
player.next_button = Button.new()
|
||||
player.awaiting_next_question = true
|
||||
question_bank.load_state = "retrying"
|
||||
player._on_random_question_failed("Connection interrupted.")
|
||||
_assert(player.awaiting_next_question, "automatic retries should preserve the pending next-question request")
|
||||
_assert(player.next_button.disabled, "next button should remain disabled while reconnecting")
|
||||
_assert(player.next_button.text == "Reconnecting...", "retry state should be visible to the user")
|
||||
question_bank.load_state = prior_state
|
||||
player.next_button.free()
|
||||
player.free()
|
||||
|
||||
|
||||
func _assert(condition: bool, message: String) -> void:
|
||||
if condition:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user