Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the retry delay and add retries count to avoid flaky "tcp_connect_timeout" test #4067

Open
wants to merge 1 commit into
base: v1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions test/test-tcp-connect-timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,47 @@ static void close_cb(uv_handle_t* handle) {
/* Verify that connecting to an unreachable address or port doesn't hang
* the event loop.
*/
TEST_IMPL(tcp_connect_timeout) {
TEST_IMPL(tcp_connect_timeout)
{
struct sockaddr_in addr;
int r;
int retry_count = 3;
int retry_delay = 100;

ASSERT(0 == uv_ip4_addr("8.8.8.8", 9999, &addr));

r = uv_timer_init(uv_default_loop(), &timer);
ASSERT(r == 0);

r = uv_timer_start(&timer, timer_cb, 50, 0);
r = uv_timer_start(&timer, timer_cb, retry_delay, 0);
ASSERT(r == 0);

r = uv_tcp_init(uv_default_loop(), &conn);
ASSERT(r == 0);

r = uv_tcp_connect(&connect_req,
&conn,
(const struct sockaddr*) &addr,
connect_cb);
if (r == UV_ENETUNREACH)
RETURN_SKIP("Network unreachable.");
ASSERT(r == 0);
do
{
r = uv_tcp_connect(&connect_req,
&conn,
(const struct sockaddr *)&addr,
connect_cb);

if (r == UV_ENETUNREACH)
{
if (--retry_count == 0)
{
RETURN_SKIP("Network unreachable after multiple retries.");
}
else
{
uv_sleep(retry_delay);
continue;
}
}

ASSERT(r == 0);
break;
} while (retry_count > 0);

r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
Expand Down