-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cadb88a
commit 1730264
Showing
8 changed files
with
148 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.