From 34146cc7af4b38a27a45e0105340ef277e70bae0 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Thu, 3 Dec 2020 12:05:11 -0800 Subject: [PATCH] disable problematic test until it gets fixed (#1065) Temporal patch for https://github.com/azure/azure-sdk-for-cpp/issues/1060. --- sdk/core/azure-core/test/ut/CMakeLists.txt | 5 + .../test/ut/transport_adapter_curl.cpp | 144 +++++++++--------- 2 files changed, 80 insertions(+), 69 deletions(-) diff --git a/sdk/core/azure-core/test/ut/CMakeLists.txt b/sdk/core/azure-core/test/ut/CMakeLists.txt index 7667ce57c..e98c19481 100644 --- a/sdk/core/azure-core/test/ut/CMakeLists.txt +++ b/sdk/core/azure-core/test/ut/CMakeLists.txt @@ -25,6 +25,11 @@ if(BUILD_TRANSPORT_CURL) endif() include(GoogleTest) + +# This symbol helps to disable tests by adding a pre-processor condition `#if !defined(TEST_DISABLED)` +# The symbol is define to disable any test surrounded with this. +add_compile_definitions(TEST_DISABLED) + add_executable ( ${TARGET_NAME} context.cpp diff --git a/sdk/core/azure-core/test/ut/transport_adapter_curl.cpp b/sdk/core/azure-core/test/ut/transport_adapter_curl.cpp index 429b736c4..d99b35289 100644 --- a/sdk/core/azure-core/test/ut/transport_adapter_curl.cpp +++ b/sdk/core/azure-core/test/ut/transport_adapter_curl.cpp @@ -8,8 +8,8 @@ #include #include -#include #include +#include using testing::ValuesIn; @@ -36,85 +36,91 @@ namespace Azure { namespace Core { namespace Test { } } // namespace - /*********************** Unique Tests for Libcurl ********************************/ - TEST_P(TransportAdapter, connectionPoolTest) - { - Azure::Core::Http::Url host("http://httpbin.org/get"); - Azure::Core::Http::CurlConnectionPool::ClearIndex(); - - auto threadRoutine = [&]() { - using namespace std::chrono_literals; - auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host); - auto response = m_pipeline->Send(Azure::Core::GetApplicationContext(), request); - checkResponseCode(response->GetStatusCode()); - auto expectedResponseBodySize = std::stoull(response->GetHeaders().at("content-length")); - CheckBodyFromBuffer(*response, expectedResponseBodySize); - std::this_thread::sleep_for(1s); - }; - - std::thread t1(threadRoutine); - std::thread t2(threadRoutine); - t1.join(); - t2.join(); - - // 2 connections must be available at this point - EXPECT_EQ(Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org"), 2); - - std::thread t3(threadRoutine); - std::thread t4(threadRoutine); - std::thread t5(threadRoutine); - t3.join(); - t4.join(); - t5.join(); - - // Two connections re-used plus one connection created - EXPECT_EQ(Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org"), 3); - -#ifdef RUN_LONG_UNIT_TESTS +/*********************** Unique Tests for Libcurl ********************************/ +// Disabling test with TEST_DISABLED. The test name cannot be changed because it depends on a +// friend class definition. Hence, it can't use the gtest DISABLE_ +#if !defined(TEST_DISABLED) + TEST_P(TransportAdapter, connectionPoolTest) { - // Test pool clean routine - std::cout << "Running Connection Pool Cleaner Test. This test takes more than 3 minutes to " - "complete." - << std::endl - << "Add compiler option -DRUN_LONG_UNIT_TESTS=OFF when building if you want to " - "skip this test." - << std::endl; + Azure::Core::Http::Url host("http://httpbin.org/get"); + Azure::Core::Http::CurlConnectionPool::ClearIndex(); - // Wait for 180 secs to make sure any previous connection is removed by the cleaner - std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 180)); - - std::cout << "First wait time done. Validating state." << std::endl; - - // index is not affected by cleaner. It does not remove index - EXPECT_EQ(Http::CurlConnectionPool::ConnectionsIndexOnPool(), 1); - // cleaner should have removed connections - EXPECT_EQ(Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org"), 0); + auto threadRoutine = [&]() { + using namespace std::chrono_literals; + auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host); + auto response = m_pipeline->Send(Azure::Core::GetApplicationContext(), request); + checkResponseCode(response->GetStatusCode()); + auto expectedResponseBodySize = std::stoull(response->GetHeaders().at("content-length")); + CheckBodyFromBuffer(*response, expectedResponseBodySize); + std::this_thread::sleep_for(1s); + }; std::thread t1(threadRoutine); std::thread t2(threadRoutine); t1.join(); t2.join(); - // wait for connection to be moved back to pool - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // 2 connections must be available at this point + EXPECT_EQ(Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org"), 2); - // 2 connections must be available at this point and one index - EXPECT_EQ(Http::CurlConnectionPool::ConnectionsIndexOnPool(), 1); - // Depending on how fast the previous requests are sent, there could be one or more - // connections in the pool. If first request is too fast, the second request will reuse the - // same connection. - EXPECT_PRED1( - [](int currentConnections) { return currentConnections > 1; }, - Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org")); + std::thread t3(threadRoutine); + std::thread t4(threadRoutine); + std::thread t5(threadRoutine); + t3.join(); + t4.join(); + t5.join(); + + // Two connections re-used plus one connection created + EXPECT_EQ(Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org"), 3); + +#ifdef RUN_LONG_UNIT_TESTS + { + // Test pool clean routine + std::cout << "Running Connection Pool Cleaner Test. This test takes more than 3 minutes + to " + "complete." + << std::endl + << "Add compiler option -DRUN_LONG_UNIT_TESTS=OFF when building if you want to + " + "skip this test." + << std::endl; + + // Wait for 180 secs to make sure any previous connection is removed by the cleaner + std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 180)); + + std::cout << "First wait time done. Validating state." << std::endl; + + // index is not affected by cleaner. It does not remove index + EXPECT_EQ(Http::CurlConnectionPool::ConnectionsIndexOnPool(), 1); + // cleaner should have removed connections + EXPECT_EQ(Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org"), 0); + + std::thread t1(threadRoutine); + std::thread t2(threadRoutine); + t1.join(); + t2.join(); + + // wait for connection to be moved back to pool + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + // 2 connections must be available at this point and one index + EXPECT_EQ(Http::CurlConnectionPool::ConnectionsIndexOnPool(), 1); + // Depending on how fast the previous requests are sent, there could be one or more + // connections in the pool. If first request is too fast, the second request will reuse the + // same connection. + EXPECT_PRED1( + [](int currentConnections) { return currentConnections > 1; }, + Http::CurlConnectionPool::ConnectionsOnPool("httpbin.org")); + } +#endif } #endif - } - /*********************** Base Transpoer Adapter Tests ******************************/ - INSTANTIATE_TEST_SUITE_P( - TransportAdapterCurlImpl, - TransportAdapter, - testing::Values(GetTransportOptions()), - GetSuffix); + /*********************** Base Transporter Adapter Tests ******************************/ + INSTANTIATE_TEST_SUITE_P( + TransportAdapterCurlImpl, + TransportAdapter, + testing::Values(GetTransportOptions()), + GetSuffix); }}} // namespace Azure::Core::Test