Skip to content

Commit

Permalink
add basic tcp
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDarigan committed Jul 10, 2023
1 parent cadb88a commit 1730264
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 212 deletions.
2 changes: 1 addition & 1 deletion WAT5.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Godot.NET.Sdk/3.3.0">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>7</LangVersion>
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="tests\**"/>
Expand Down
2 changes: 1 addition & 1 deletion addons/WAT/gui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ rect_min_size = Vector2( 160, 0 )
size_flags_horizontal = 0
size_flags_vertical = 0
min_value = 1.0
max_value = 7.0
max_value = 11.0
value = 1.0
align = 1
prefix = "Run on"
Expand Down
35 changes: 7 additions & 28 deletions addons/WAT/network/test_client.gd
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
extends "res://addons/WAT/network/test_network.gd"

func _ready() -> void:
custom_multiplayer.connect("connection_failed", self, "_on_connection_failed")
if _error(_peer.create_client(IPAddress, PORT)) == OK:
custom_multiplayer.network_peer = _peer

func _on_connection_failed() -> void:
push_warning("TestClient could not connect to TestServer")

puppet func _on_tests_received_from_server(tests: Array, repeat: int, thread_count: int) -> void:
var results: Array = yield(get_parent().run(tests, repeat, thread_count, self), "completed")
rpc_id(MASTER, "_on_results_received_from_client", results)

# LiveWire Functions
func on_test_script_started(data: Dictionary) -> void:
rpc_id(MASTER, "_on_test_script_started", data)

func on_test_script_finished(data: Dictionary) -> void:
rpc_id(MASTER, "_on_test_script_finished", data)

func on_test_method_started(data: Dictionary) -> void:
rpc_id(MASTER, "_on_test_method_started", data)

func on_test_method_finished(data: Dictionary) -> void:
rpc_id(MASTER, "_on_test_method_finished", data)
var peer: StreamPeerTCP = StreamPeerTCP.new()

func on_asserted(data: Dictionary) -> void:
rpc_id(MASTER, "_on_asserted", data)
func _ready() -> void:
peer.connect_to_host("127.0.0.1", 8080)

func on_test_method_described(data: Dictionary) -> void:
rpc_id(MASTER, "_on_test_method_described", data)
func _process(delta: float) -> void:
if peer.is_connected_to_host() and peer.get_available_bytes() > 0:
print(peer.get_utf8_string())
peer.put_utf8_string("Response")
83 changes: 22 additions & 61 deletions addons/WAT/network/test_server.gd
Original file line number Diff line number Diff line change
@@ -1,68 +1,29 @@
tool
extends "res://addons/WAT/network/test_network.gd"

signal network_peer_connected
signal results_received
# -> Create Test Suite
# -> Return Suite Created
# -> Run Test Method
# <- Return Test Result

enum STATE { SENDING, RECEIVING, DISCONNECTED }
# TCP stuff
var server: TCP_Server = TCP_Server.new()
var client: StreamPeerTCP
var port = 8080

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
var buffer = ["Request"]

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
# Timeout is 10 minutes.
_peer.set_peer_timeout(id, 600000, 601000, 602000)
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 kick_current_peer():
var kicked = false
if _peer_id in custom_multiplayer.get_network_connected_peers():
_on_results_received_from_client([])
kicked = true
return kicked

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)

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)

master func _on_test_method_finished(data: Dictionary) -> void:
results_view.on_test_method_finished(data)

master func _on_asserted(data: Dictionary) -> void:
results_view.on_asserted(data)

master func _on_test_method_described(data: Dictionary) -> void:
results_view.on_test_method_described(data)
server.listen(port, "127.0.0.1")

func _process(delta: float) -> void:
if server.is_connection_available():
client = server.take_connection()
if client and client.get_available_bytes() > 0:
print(client.get_utf8_string())
if client and not buffer.empty():
client.put_utf8_string(buffer.pop_back())

func _exit_tree() -> void:
client.disconnect_from_host()
server.stop()
2 changes: 1 addition & 1 deletion addons/WAT/runner/TestRunner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ func _repeat(tests: Array, repeat: int) -> Array:
for test in tests:
duplicates.append(test)
duplicates += tests
return duplicates
return duplicates
16 changes: 8 additions & 8 deletions addons/WAT/ui/gui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func setup_editor_context(plugin, goto_func: FuncRef, filesystem: Reference) ->
TestMenu.filesystem = _filesystem
_filesystem.update()
TestMenu.update_menus()
Server.results_view = Results
#Server.results_view = Results

# Setup tests for display. Returns false if run should be terminated.
func _setup_display(tests: Array) -> bool:
Expand Down Expand Up @@ -103,19 +103,19 @@ func _on_debug_pressed(data = _filesystem.root, run_mode: int = RUN_ALL.NOT_RUN_
Results.clear()
data = build(data)

if Server.kick_current_peer():
_plugin.get_editor_interface().stop_playing_scene()
# if Server.kick_current_peer():
# _plugin.get_editor_interface().stop_playing_scene()
var tests: Array = data.get_tests()
if _setup_display(tests):
_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")
_plugin.get_editor_interface().stop_playing_scene()
_on_test_run_finished(results)
# yield(Server, "network_peer_connected")
# Server.send_tests(tests, Repeats.value, Threads.value)
# var results: Array = yield(Server, "results_received")
# _plugin.get_editor_interface().stop_playing_scene()
# _on_test_run_finished(results)

func build(data = null):
if not Engine.is_editor_hint():
Expand Down
4 changes: 0 additions & 4 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ config/name="WAT5"
run/main_scene="res://addons/WAT/gui.tscn"
config/icon="res://icon.svg"

[debug]

settings/stdout/verbose_stdout=true

[editor_plugins]

enabled=PoolStringArray( "res://addons/WAT/plugin.cfg" )
Expand Down
Loading

0 comments on commit 1730264

Please sign in to comment.