X Tutup
Skip to content

Add unit tests for StreamPeerTCP#102064

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
wheatear-dev:test-stream-peer-tcp
Oct 23, 2025
Merged

Add unit tests for StreamPeerTCP#102064
Repiteo merged 1 commit intogodotengine:masterfrom
wheatear-dev:test-stream-peer-tcp

Conversation

@wheatear-dev
Copy link
Contributor

@wheatear-dev wheatear-dev commented Jan 26, 2025

Adds unit tests for StreamPeerTCP, using a mock implementation of NetSocket (#43440).

Includes:

  • Boundary testing of port bindings
  • State transitions (e.g. receiving a FIN message)
  • Streaming ascii-encoded data on:
    • StreamPeerTCP::put_data()
    • StreamPeerTCP::get_data()

Several public methods on StreamPeerTCP are tested, but more remain untested - this can be addressed in later PR's if required.

Thanks! 😌

@wheatear-dev wheatear-dev force-pushed the test-stream-peer-tcp branch 2 times, most recently from a4a8762 to 2b51b82 Compare March 21, 2025 17:04
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on Linux (rebased on top of master 9dde568), I get a build error:

In file included from tests/test_main.cpp:63:
./tests/core/io/test_stream_peer_tcp.h: In function 'void TestStreamPeerTCP::DOCTEST_ANON_FUNC_880()':
./tests/core/io/test_stream_peer_tcp.h:264:27: error: 'class Vector<unsigned char>' has no member named 'resize_zeroed'
  264 |                 send_data.resize_zeroed(expected.length());
      |                           ^~~~~~~~~~~~~
In file included from ./core/variant/binder_common.h:34,
                 from ./core/object/method_bind.h:33,
                 from ./core/object/class_db.h:33,
                 from ./core/object/ref_counted.h:33,
                 from ./core/io/dir_access.h:33,
                 from tests/test_main.cpp:34:
./core/object/object.h: In instantiation of 'static T* Object::cast_to(Object*) [with T = NetSocket]':
./core/object/ref_counted.h:145:40:   required from 'void Ref<T>::operator=(const Ref<T_Other>&) [with T_Other = TestStreamPeerTCP::MockNetSocket; T = NetSocket]'
  145 |                 ref_pointer<false>(Object::cast_to<T>(p_from.ptr()));
      |                                    ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
./core/object/ref_counted.h:182:18:   required from 'Ref<T>::Ref(const Ref<T_Other>&) [with T_Other = TestStreamPeerTCP::MockNetSocket; T = NetSocket]'
  182 |                 this->operator=(p_from);
      |                 ~~~~~~~~~~~~~~~^~~~~~~~
./tests/core/io/test_stream_peer_tcp.h:192:21:   required from here
  192 |         spt->accept_socket(ns, peer_ip, peer_port);
      |                            ^~
./core/object/object.h:799:36: error: static assertion failed: T must use GDCLASS or GDSOFTCLASS
  799 |                 static_assert(std::is_same_v<std::decay_t<T>, typename T::self_type>, "T must use GDCLASS or GDSOFTCLASS");
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./core/object/object.h:799:36: note: 'std::is_same_v<NetSocket, RefCounted>' evaluates to false
scons: *** [bin/obj/tests/test_main.linuxbsd.editor.x86_64.o] Error 1
scons: building terminated because of errors.

@wheatear-dev wheatear-dev force-pushed the test-stream-peer-tcp branch 2 times, most recently from 2100467 to 6ca1c88 Compare September 19, 2025 14:32
@wheatear-dev wheatear-dev requested a review from a team as a code owner September 19, 2025 14:32
@wheatear-dev wheatear-dev force-pushed the test-stream-peer-tcp branch 2 times, most recently from f211d1d to 189c773 Compare September 21, 2025 06:01
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great now 🙂 Code looks good to me.

@wheatear-dev wheatear-dev force-pushed the test-stream-peer-tcp branch 2 times, most recently from e3f525a to bc83ad4 Compare September 27, 2025 18:04
@Repiteo Repiteo removed this from the 4.x milestone Oct 21, 2025
@Repiteo Repiteo added this to the 4.6 milestone Oct 21, 2025
@Repiteo
Copy link
Contributor

Repiteo commented Oct 21, 2025

Needs a rebase; several TCP functions have been updated, so MockNetSocket fails to override as expected

@wheatear-dev
Copy link
Contributor Author

Needs a rebase; several TCP functions have been updated, so MockNetSocket fails to override as expected

Hi @Repiteo

I have rebased, and ported over to the new code for NetSocket. After this rebase, an error message is now appearing, as below:

bin/godot.macos.editor.arm64 --test                                
[doctest] doctest version is "2.4.12"
[doctest] run with "--help" for options
ERROR: Connection to remote host failed!
   at: connect_to_host (core/io/stream_peer_uds.cpp:86)
===============================================================================
[doctest] test cases:    1258 |    1258 passed | 0 failed | 3 skipped
[doctest] assertions: 2453766 | 2453766 passed | 0 failed |
[doctest] Status: SUCCESS!

But this doesn't appear to be emitted from one of my test cases:

bin/godot.macos.editor.arm64 --test --test-case='*[StreamPeerTCP]*'
[doctest] doctest version is "2.4.12"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases:  3 |  3 passed | 0 failed | 1258 skipped
[doctest] assertions: 23 | 23 passed | 0 failed |
[doctest] Status: SUCCESS!

@Repiteo Repiteo merged commit 1c41e93 into godotengine:master Oct 23, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 23, 2025

Thanks!

@wheatear-dev wheatear-dev deleted the test-stream-peer-tcp branch October 25, 2025 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup