Skip to content

Commit

Permalink
[tests] Fixed connection timeout test to not reuse broken socket (#1712)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris committed Dec 15, 2020
1 parent 05a803c commit c507c5b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/test_connection_timeout.cpp
Expand Up @@ -172,20 +172,20 @@ TEST_F(TestConnectionTimeout, Nonblocking) {
*/
TEST_F(TestConnectionTimeout, BlockingLoop)
{
const SRTSOCKET client_sock = srt_create_socket();
ASSERT_GT(client_sock, 0); // socket_id should be > 0

// Set connection timeout to 999 ms to reduce the test execution time.
// Also need to hit a time point between two threads:
// srt_connect will check TTL every second,
// CRcvQueue::worker will wait on a socket for 10 ms.
// Need to have a condition, when srt_connect will process the timeout.
const int connection_timeout_ms = 999;
EXPECT_EQ(srt_setsockopt(client_sock, 0, SRTO_CONNTIMEO, &connection_timeout_ms, sizeof connection_timeout_ms), SRT_SUCCESS);

const sockaddr* psa = reinterpret_cast<const sockaddr*>(&m_sa);
const int connection_timeout_ms = 999;
for (int i = 0; i < 10; ++i)
{
const SRTSOCKET client_sock = srt_create_socket();
ASSERT_GT(client_sock, 0); // socket_id should be > 0

// Set connection timeout to 999 ms to reduce the test execution time.
// Also need to hit a time point between two threads:
// srt_connect will check TTL every second,
// CRcvQueue::worker will wait on a socket for 10 ms.
// Need to have a condition, when srt_connect will process the timeout.
EXPECT_EQ(srt_setsockopt(client_sock, 0, SRTO_CONNTIMEO, &connection_timeout_ms, sizeof connection_timeout_ms), SRT_SUCCESS);

EXPECT_EQ(srt_connect(client_sock, psa, sizeof m_sa), SRT_ERROR);

const int error_code = srt_getlasterror(nullptr);
Expand All @@ -196,9 +196,9 @@ TEST_F(TestConnectionTimeout, BlockingLoop)
<< error_code << " " << srt_getlasterror_str() << "\n";
break;
}
}

EXPECT_EQ(srt_close(client_sock), SRT_SUCCESS);
EXPECT_EQ(srt_close(client_sock), SRT_SUCCESS);
}
}


0 comments on commit c507c5b

Please sign in to comment.