Skip to content

Commit 7844f77

Browse files
committed
Adjust DisconnectHandle test.
- Signal disconnecting is now handled automatically by Godot Runtime.
1 parent 41fded1 commit 7844f77

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

itest/rust/src/builtin_tests/containers/signal_disconnect_test.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ fn handle_recognizes_direct_object_disconnect() {
154154

155155
#[itest]
156156
fn test_handle_after_freeing_broadcaster() {
157-
test_freed_nodes(true);
157+
test_freed_nodes_handles(true);
158158
}
159159

160160
#[itest]
161161
fn test_handle_after_freeing_receiver() {
162-
test_freed_nodes(false);
162+
test_freed_nodes_handles(false);
163163
}
164164

165165
// Helper functions:
@@ -233,7 +233,7 @@ fn test_handle_recognizes_non_valid_state(disconnect_function: impl FnOnce(&mut
233233
obj.free();
234234
}
235235

236-
fn test_freed_nodes(free_broadcaster_first: bool) {
236+
fn test_freed_nodes_handles(free_broadcaster_first: bool) {
237237
let broadcaster = SignalDisc::new_alloc();
238238
let receiver = SignalDisc::new_alloc();
239239

@@ -251,21 +251,13 @@ fn test_freed_nodes(free_broadcaster_first: bool) {
251251
};
252252

253253
// Free one of the nodes, and check if the handle thinks the objects are connected.
254-
// If the broadcaster is freed, its signals to other objects is implicitly freed as well. Thus, the handle should not be connected.
255-
// If the receiver is freed, the connection between the valid broadcaster and the non-valid freed object still exists.
256-
// In the latter case, the connection can - and probably should - be freed with disconnect().
254+
// In both cases godot runtime should handle disconnecting the signals.
257255
to_free.free();
258-
let is_connected = handle.is_connected();
259-
assert_ne!(
260-
free_broadcaster_first, is_connected,
261-
"Handle should only return false if broadcasting is freed!"
262-
);
263-
264-
// It should be possible to disconnect a connection between a valid broadcaster and a non-valid receiver.
265-
// If the connection is not valid (e.g. because of freed broadcaster), calling disconnect() should panic.
266-
if is_connected {
267-
handle.disconnect();
268-
} else {
256+
assert!(!handle.is_connected());
257+
258+
// Calling disconnect() on already disconnected handle should panic in the Debug mode.
259+
// Otherwise, in release mode, the error will happen in Godot runtime.
260+
if cfg!(debug_assertions) {
269261
expect_panic("Disconnected invalid handle!", || {
270262
handle.disconnect();
271263
});

0 commit comments

Comments
 (0)