Skip to content

Commit

Permalink
Merge pull request watplugin#318 from RailKill/fix-debug-breaking-on-…
Browse files Browse the repository at this point in the history
…crash

Use signals for GUI debug to prevent endless yields caused by TestRunner crashes or debugger force stop
  • Loading branch information
AlexDarigan authored Dec 17, 2021
2 parents ee8f55b + e346ff0 commit 264807b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 20 additions & 5 deletions addons/WAT/network/test_server.gd
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
tool
extends "res://addons/WAT/network/test_network.gd"

enum STATE { SENDING, RECEIVING }
signal network_peer_connected
signal results_received

enum STATE { SENDING, RECEIVING, DISCONNECTED }

var _peer_id: int
# Store incoming cases from client in case of abrupt termination.
var caselist: Array = []
var results_view: TabContainer
var status: int = STATE.DISCONNECTED

func _ready() -> void:
if not Engine.is_editor_hint():
return
custom_multiplayer.connect("network_peer_connected", self, "_on_network_peer_connected")
custom_multiplayer.connect("network_peer_disconnected", self, "_on_network_peer_disconnected")
if _error(_peer.create_server(PORT, MAXCLIENTS)) == OK:
custom_multiplayer.network_peer = _peer

func _on_network_peer_connected(id: int) -> void:
_peer_id = id
_peer.set_peer_timeout(id, 59000, 60000, 61000)
_peer.set_peer_timeout(id, 1000, 2000, 3000)
emit_signal("network_peer_connected")


func _on_network_peer_disconnected(_id: int) -> void:
if status == STATE.SENDING:
emit_signal("results_received", caselist)
caselist.clear()
status = STATE.DISCONNECTED

func send_tests(testdir: Array, repeat: int, thread_count: int) -> void:
status = STATE.SENDING
rpc_id(_peer_id, "_on_tests_received_from_server", testdir, repeat, thread_count)

master func _on_results_received_from_client(results: Array = []) -> void:
status = STATE.RECEIVING
emit_signal("results_received", results)
_peer.disconnect_peer(_peer_id, true)

var results_view: TabContainer

master func _on_test_script_started(data: Dictionary) -> void:
results_view.on_test_script_started(data)

master func _on_test_script_finished(data: Dictionary) -> void:
results_view.on_test_script_finished(data)
caselist.append(data)

master func _on_test_method_started(data: Dictionary) -> void:
results_view.on_test_method_started(data)
Expand Down
12 changes: 7 additions & 5 deletions addons/WAT/ui/gui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func setup_editor_context(plugin, build: FuncRef, goto_func: FuncRef, filesystem
_filesystem.update()
TestMenu.update_menus()
Server.results_view = Results
Server.connect("results_received", self, "_on_test_run_finished")

func _on_run_pressed(data = _filesystem.root) -> void:
Results.clear()
Expand Down Expand Up @@ -102,13 +103,14 @@ func _on_debug_pressed(data = _filesystem.root) -> void:
_plugin.get_editor_interface().play_custom_scene("res://addons/WAT/runner/TestRunner.tscn")
if Settings.is_bottom_panel():
_plugin.make_bottom_panel_item_visible(self)
yield(Server, "network_peer_connected")
Server.send_tests(tests, Repeats.value, Threads.value)
var results: Array = yield(Server, "results_received") #results_received
_plugin.get_editor_interface().stop_playing_scene() # Check if this works exported
_on_test_run_finished(results)
# Reconnect peer connected signal to send current tests.
if Server.is_connected("network_peer_connected", Server, "send_tests"):
Server.disconnect("network_peer_connected", Server, "send_tests")
Server.connect("network_peer_connected", Server, "send_tests",
[tests, Repeats.value, Threads.value])

func _on_test_run_finished(results: Array) -> void:
_plugin.get_editor_interface().stop_playing_scene() # Check if this works exported
Summary.summarize(results)
JUnitXML.write(results, Settings, Summary.time_taken)
_filesystem.failed.update(results)
Expand Down

0 comments on commit 264807b

Please sign in to comment.