Skip to content

Commit

Permalink
[tests] Added yielding for tests that spawn a thread for connect (#2883
Browse files Browse the repository at this point in the history
…).
  • Loading branch information
ethouris authored Feb 21, 2024
1 parent bed5488 commit 07e22ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 28 additions & 1 deletion test/test_fec_rebuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,12 @@ TEST(TestFEC, Connection)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

SRTSOCKET la[] = { l };
// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

// Given 2s timeout for accepting as it has occasionally happened with Travis
// that 1s might not be enough.
SRTSOCKET la[] = { l };
SRTSOCKET a = srt_accept_bond(la, 1, 2000);
ASSERT_NE(a, SRT_ERROR);
EXPECT_EQ(connect_res.get(), SRT_SUCCESS);
Expand Down Expand Up @@ -362,6 +365,9 @@ TEST(TestFEC, ConnectionReorder)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

SRTSOCKET la[] = { l };
SRTSOCKET a = srt_accept_bond(la, 1, 2000);
ASSERT_NE(a, SRT_ERROR);
Expand Down Expand Up @@ -417,6 +423,9 @@ TEST(TestFEC, ConnectionFull1)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

SRTSOCKET la[] = { l };
SRTSOCKET a = srt_accept_bond(la, 1, 2000);
ASSERT_NE(a, SRT_ERROR);
Expand Down Expand Up @@ -472,6 +481,9 @@ TEST(TestFEC, ConnectionFull2)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

SRTSOCKET la[] = { l };
SRTSOCKET a = srt_accept_bond(la, 1, 2000);
ASSERT_NE(a, SRT_ERROR);
Expand Down Expand Up @@ -527,6 +539,9 @@ TEST(TestFEC, ConnectionMess)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

SRTSOCKET la[] = { l };
SRTSOCKET a = srt_accept_bond(la, 1, 2000);
ASSERT_NE(a, SRT_ERROR);
Expand Down Expand Up @@ -580,6 +595,9 @@ TEST(TestFEC, ConnectionForced)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

SRTSOCKET la[] = { l };
SRTSOCKET a = srt_accept_bond(la, 1, 2000);
ASSERT_NE(a, SRT_ERROR);
Expand Down Expand Up @@ -630,6 +648,9 @@ TEST(TestFEC, RejectionConflict)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

EXPECT_EQ(connect_res.get(), SRT_ERROR);
EXPECT_EQ(srt_getrejectreason(s), SRT_REJ_FILTER);

Expand Down Expand Up @@ -671,6 +692,9 @@ TEST(TestFEC, RejectionIncompleteEmpty)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

EXPECT_EQ(connect_res.get(), SRT_ERROR);
EXPECT_EQ(srt_getrejectreason(s), SRT_REJ_FILTER);

Expand Down Expand Up @@ -716,6 +740,9 @@ TEST(TestFEC, RejectionIncomplete)
return srt_connect(s, (sockaddr*)& sa, sizeof(sa));
});

// Make sure that the async call to srt_connect() is already kicked.
std::this_thread::yield();

EXPECT_EQ(connect_res.get(), SRT_ERROR);
EXPECT_EQ(srt_getrejectreason(s), SRT_REJ_FILTER);

Expand Down
3 changes: 3 additions & 0 deletions test/test_socket_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class TestSocketOptions
};
auto accept_res = async(launch::async, accept_async, m_listen_sock);

// Make sure the thread was kicked
this_thread::yield();

const int connect_res = Connect();
EXPECT_EQ(connect_res, SRT_SUCCESS);

Expand Down

0 comments on commit 07e22ca

Please sign in to comment.