The previous tests never compiled: they used GUT's assert functions, Godot 3 APIs and reassigned autoload functions, so no test ran. - 90 tests: unit tests for the playlist, songs, player scoring, time formatting, search and the server client, plus integration tests that run MainWindow and SyncWindow against a fake server - Keybind tests check that Alt+<number> and Ctrl+Alt+<number> keep following the player rows while players are added and removed - run_tests.sh finds Godot and runs the suite headless (~10 seconds) - CI runs the tests before the build job in gitea-build.yaml; the separate test.yml used a GitHub action that does not exist - GdUnit4 is committed instead of ignored, since the project enables it, and .gitea/ is no longer ignored - Exported builds leave out tests/ and addons/gdUnit4/
56 lines
1.9 KiB
GDScript
56 lines
1.9 KiB
GDScript
class_name GdUnitTcpNode
|
|
extends Node
|
|
|
|
## Maximum size of a single RPC payload. Godot's default of 64 KiB is too small for larger test
|
|
## events (e.g. reports with long stack traces), so it is raised here. Kept modest because
|
|
## `PacketPeerStream` allocates its buffers eagerly at this size, per connection.
|
|
const MAX_PACKET_SIZE := 2 * 1024 * 1024
|
|
|
|
# `PacketPeerStream` reassembles length-prefixed packets from a raw `StreamPeerTCP` byte stream,
|
|
# buffering partial reads across calls instead of assuming a full message always arrives at once.
|
|
var _packets := _new_packet_peer()
|
|
|
|
|
|
static func _new_packet_peer() -> PacketPeerStream:
|
|
var packet_peer := PacketPeerStream.new()
|
|
packet_peer.input_buffer_max_size = MAX_PACKET_SIZE
|
|
packet_peer.output_buffer_max_size = MAX_PACKET_SIZE
|
|
return packet_peer
|
|
|
|
|
|
func rpc_send(stream: StreamPeerTCP, data: RPC) -> void:
|
|
_packets.stream_peer = stream
|
|
var payload := data.serialize().to_utf16_buffer()
|
|
var status_code := _packets.put_packet(payload)
|
|
if status_code != OK:
|
|
push_error("'rpc_send:' Can't put_packet(), error: %s" % error_string(status_code))
|
|
|
|
|
|
func receive_packages(stream: StreamPeerTCP, rpc_cb: Callable = noop) -> Array[RPC]:
|
|
var received_packages: Array[RPC] = []
|
|
if stream.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
|
return received_packages
|
|
|
|
_packets.stream_peer = stream
|
|
while _packets.get_available_packet_count() > 0:
|
|
var payload := _packets.get_packet()
|
|
var status_code := _packets.get_packet_error()
|
|
if status_code != OK:
|
|
push_error("'receive_packages:' Can't get_packet(), error: %s" % error_string(status_code))
|
|
continue
|
|
|
|
var json := payload.get_string_from_utf16()
|
|
if json.is_empty():
|
|
push_warning("json is empty, can't process data")
|
|
continue
|
|
var data := RPC.deserialize(json)
|
|
if data == null:
|
|
continue
|
|
received_packages.append(data)
|
|
rpc_cb.call(data)
|
|
return received_packages
|
|
|
|
|
|
static func noop(_rpc_data: RPC) -> void:
|
|
pass
|