NEO-22: Fix GdUnit warnings in position_authority_client_test
Rename mock variables to avoid shadowing GdUnitTestSuite.mock, drop redundant await on synchronous assert_signal chains, and ignore unused request_completed on HangingHttpTransport (API parity only).pull/42/head
parent
a4095cb9bf
commit
a7e6a5af59
|
|
@ -31,6 +31,7 @@ class MockHttpTransport:
|
|||
# Holds _busy without completing (never emits request_completed).
|
||||
class HangingHttpTransport:
|
||||
extends Node
|
||||
@warning_ignore("unused_signal")
|
||||
signal request_completed(
|
||||
result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray
|
||||
)
|
||||
|
|
@ -46,72 +47,72 @@ class HangingHttpTransport:
|
|||
return OK
|
||||
|
||||
|
||||
func _make_client(mock: Node) -> Node:
|
||||
func _make_client(http_transport: Node) -> Node:
|
||||
var c: Node = PositionAuthorityTestDouble.new()
|
||||
c.set("injected_http", mock)
|
||||
auto_free(mock)
|
||||
c.set("injected_http", http_transport)
|
||||
auto_free(http_transport)
|
||||
auto_free(c)
|
||||
add_child(c)
|
||||
return c
|
||||
|
||||
|
||||
func test_sync_boot_get_200_emits_snap() -> void:
|
||||
var mock := MockHttpTransport.new()
|
||||
mock.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":{"x":1,"y":0.9,"z":-5}}')
|
||||
var c := _make_client(mock)
|
||||
var transport := MockHttpTransport.new()
|
||||
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":{"x":1,"y":0.9,"z":-5}}')
|
||||
var c := _make_client(transport)
|
||||
monitor_signals(c)
|
||||
c.sync_from_server()
|
||||
await assert_signal(c).is_emitted(
|
||||
assert_signal(c).is_emitted(
|
||||
"authoritative_position_received", Vector3(1.0, 0.9, -5.0), true
|
||||
)
|
||||
|
||||
|
||||
func test_sync_boot_get_200_malformed_position_does_not_emit() -> void:
|
||||
var mock := MockHttpTransport.new()
|
||||
mock.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":"invalid"}')
|
||||
var c := _make_client(mock)
|
||||
var transport := MockHttpTransport.new()
|
||||
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":"invalid"}')
|
||||
var c := _make_client(transport)
|
||||
monitor_signals(c)
|
||||
c.sync_from_server()
|
||||
await assert_signal(c).wait_until(400).is_not_emitted("authoritative_position_received")
|
||||
assert_signal(c).wait_until(400).is_not_emitted("authoritative_position_received")
|
||||
|
||||
|
||||
func test_move_stream_post_400_emits_move_rejected_then_boot_get() -> void:
|
||||
var mock := MockHttpTransport.new()
|
||||
mock.enqueue(HTTPRequest.RESULT_SUCCESS, 400, '{"reasonCode":"vertical_step_exceeded"}')
|
||||
mock.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":{"x":0,"y":0.9,"z":0}}')
|
||||
var c := _make_client(mock)
|
||||
var transport := MockHttpTransport.new()
|
||||
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 400, '{"reasonCode":"vertical_step_exceeded"}')
|
||||
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":{"x":0,"y":0.9,"z":0}}')
|
||||
var c := _make_client(transport)
|
||||
monitor_signals(c)
|
||||
c.submit_stream_targets([Vector3(1.0, 2.0, 3.0)])
|
||||
await assert_signal(c).is_emitted("move_rejected", "vertical_step_exceeded")
|
||||
await assert_signal(c).is_emitted(
|
||||
assert_signal(c).is_emitted("move_rejected", "vertical_step_exceeded")
|
||||
assert_signal(c).is_emitted(
|
||||
"authoritative_position_received", Vector3(0.0, 0.9, 0.0), true
|
||||
)
|
||||
|
||||
|
||||
func test_move_stream_post_400_without_reason_emits_unknown() -> void:
|
||||
var mock := MockHttpTransport.new()
|
||||
mock.enqueue(HTTPRequest.RESULT_SUCCESS, 400, "{}")
|
||||
mock.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":{"x":1,"y":0.9,"z":1}}')
|
||||
var c := _make_client(mock)
|
||||
var transport := MockHttpTransport.new()
|
||||
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 400, "{}")
|
||||
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"position":{"x":1,"y":0.9,"z":1}}')
|
||||
var c := _make_client(transport)
|
||||
monitor_signals(c)
|
||||
c.submit_stream_targets([Vector3.ZERO])
|
||||
await assert_signal(c).is_emitted("move_rejected", "unknown")
|
||||
await assert_signal(c).is_emitted(
|
||||
assert_signal(c).is_emitted("move_rejected", "unknown")
|
||||
assert_signal(c).is_emitted(
|
||||
"authoritative_position_received", Vector3(1.0, 0.9, 1.0), true
|
||||
)
|
||||
|
||||
|
||||
func test_second_sync_while_busy_is_ignored() -> void:
|
||||
var mock := HangingHttpTransport.new()
|
||||
var c := _make_client(mock)
|
||||
var transport := HangingHttpTransport.new()
|
||||
var c := _make_client(transport)
|
||||
c.sync_from_server()
|
||||
c.sync_from_server()
|
||||
assert_that(mock.request_count).is_equal(1)
|
||||
assert_that(transport.request_count).is_equal(1)
|
||||
|
||||
|
||||
func test_move_stream_post_200_does_not_emit_position() -> void:
|
||||
var mock := MockHttpTransport.new()
|
||||
mock.enqueue(
|
||||
var transport := MockHttpTransport.new()
|
||||
transport.enqueue(
|
||||
HTTPRequest.RESULT_SUCCESS,
|
||||
200,
|
||||
(
|
||||
|
|
@ -119,7 +120,7 @@ func test_move_stream_post_200_does_not_emit_position() -> void:
|
|||
+ '"sequence":3}'
|
||||
)
|
||||
)
|
||||
var c := _make_client(mock)
|
||||
var c := _make_client(transport)
|
||||
monitor_signals(c)
|
||||
c.submit_stream_targets([Vector3(-4.9, 0.9, -5.0)])
|
||||
await assert_signal(c).wait_until(400).is_not_emitted("authoritative_position_received")
|
||||
assert_signal(c).wait_until(400).is_not_emitted("authoritative_position_received")
|
||||
|
|
|
|||
Loading…
Reference in New Issue