Skip to content

Commit

Permalink
Merge pull request godotengine#99960 from pafuent/fixing_tcp_server_f…
Browse files Browse the repository at this point in the history
…lappy_disconnect_test

Fix `TCPServer` "Should disconnect client" test
  • Loading branch information
akien-mga authored Dec 6, 2024
2 parents eb51030 + df2c2ca commit aa8d9b8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/core/io/test_tcp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ Error poll(Ref<StreamPeerTCP> p_client) {
const uint64_t time = OS::get_singleton()->get_ticks_usec();
Error err = p_client->poll();
while (err != Error::OK && (OS::get_singleton()->get_ticks_usec() - time) < MAX_WAIT_USEC) {
err = p_client->poll();
OS::get_singleton()->delay_usec(SLEEP_DURATION);
err = p_client->poll();
}
return err;
}
Expand Down Expand Up @@ -183,8 +183,8 @@ TEST_CASE("[TCPServer] When stopped shouldn't accept new connections") {
time = OS::get_singleton()->get_ticks_usec();
Error err = new_client->poll();
while (err != Error::OK && err != Error::ERR_CONNECTION_ERROR && (OS::get_singleton()->get_ticks_usec() - time) < MAX_WAIT_USEC) {
err = new_client->poll();
OS::get_singleton()->delay_usec(SLEEP_DURATION);
err = new_client->poll();
}
REQUIRE((err == Error::OK || err == Error::ERR_CONNECTION_ERROR));
StreamPeerTCP::Status status = new_client->get_status();
Expand All @@ -210,7 +210,10 @@ TEST_CASE("[TCPServer] Should disconnect client") {
server->stop();
CHECK_FALSE(server->is_listening());

client->put_string(hello_world);
// Reading for a closed connection will print an error.
ERR_PRINT_OFF;
CHECK_EQ(client->get_string(), String());
ERR_PRINT_ON;
REQUIRE_EQ(poll(client), Error::OK);
CHECK_EQ(client->get_status(), StreamPeerTCP::STATUS_NONE);
}
Expand Down

0 comments on commit aa8d9b8

Please sign in to comment.