Http Transport perf test (#5309)
* mroe quotes * dssf * sqa * first identity test no caching * cache no cache * cleanup cache shortcircuit * some cleanup * http test 1 * Update sdk/core/perf/src/base_test.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * PR comments * remove cache option * wqq * dsd * saa * wqq * dfs * clang * http get post curl winhttp * Update sdk/core/perf/inc/azure/perf/dynamic_test_options.hpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * rtter * PR comments * PT comments * clang * http transport test * Update sdk/core/perf/src/base_test.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * PR comments * remove cache option * wqq * dsd * saa * wqq * dfs * clang * http get post curl winhttp * rtter * PR comments * PT comments * clang * http transport test * PR comments * clangs --------- Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>
This commit is contained in:
parent
02882f9141
commit
4f6cc88004
@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
set(
|
||||
AZURE_CORE_PERF_TEST_HEADER
|
||||
inc/azure/core/test/http_transport_test.hpp
|
||||
inc/azure/core/test/nullable_test.hpp
|
||||
inc/azure/core/test/uuid_test.hpp
|
||||
)
|
||||
|
||||
@ -0,0 +1,150 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Test the HTTP send performance.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../../core/perf/inc/azure/perf.hpp"
|
||||
|
||||
#include <azure/core.hpp>
|
||||
#if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
|
||||
#include <azure/core/http/curl_transport.hpp>
|
||||
#endif
|
||||
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
|
||||
#include <azure/core/http/win_http_transport.hpp>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Azure { namespace Core { namespace Test {
|
||||
|
||||
/**
|
||||
* @brief Measure the HTTP transport performance.
|
||||
*/
|
||||
class HTTPTransportTest : public Azure::Perf::PerfTest {
|
||||
|
||||
std::string m_target;
|
||||
std::shared_ptr<Azure::Core::Http::HttpTransport> m_transport;
|
||||
Azure::Core::Http::HttpMethod m_httpMethod = Azure::Core::Http::HttpMethod::Get;
|
||||
|
||||
void GetRequest() const
|
||||
{
|
||||
auto httpRequest = Azure::Core::Http::Request(m_httpMethod, Azure::Core::Url(m_target));
|
||||
Azure::Core::Context context;
|
||||
auto response = m_transport->Send(httpRequest, context);
|
||||
// Make sure to pull all bytes from network.
|
||||
auto body = response->ExtractBodyStream()->ReadToEnd();
|
||||
}
|
||||
|
||||
void PostRequest() const
|
||||
{
|
||||
std::string payload = "{}";
|
||||
Azure::Core::IO::MemoryBodyStream payloadStream(
|
||||
reinterpret_cast<const uint8_t*>(payload.data()), payload.size());
|
||||
auto httpRequest
|
||||
= Azure::Core::Http::Request(m_httpMethod, Azure::Core::Url(m_target), &payloadStream);
|
||||
Azure::Core::Context context;
|
||||
auto response = m_transport->Send(httpRequest, context);
|
||||
// Make sure to pull all bytes from network.
|
||||
auto body = response->ExtractBodyStream()->ReadToEnd();
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new HTTPTransportTest test.
|
||||
*
|
||||
* @param options The test options.
|
||||
*/
|
||||
HTTPTransportTest(Azure::Perf::TestOptions options) : PerfTest(options) {}
|
||||
|
||||
void Setup() override
|
||||
{
|
||||
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
|
||||
if ("winhttp" == m_options.GetMandatoryOption<std::string>("Transport"))
|
||||
{
|
||||
|
||||
Azure::Core::Http::WinHttpTransportOptions transportOptions;
|
||||
transportOptions.IgnoreInvalidCertificateCommonName = true;
|
||||
transportOptions.IgnoreUnknownCertificateAuthority = true;
|
||||
m_transport = std::make_shared<Azure::Core::Http::WinHttpTransport>(transportOptions);
|
||||
}
|
||||
#endif
|
||||
#if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
|
||||
if ("curl" == m_options.GetMandatoryOption<std::string>("Transport"))
|
||||
{
|
||||
|
||||
Azure::Core::Http::CurlTransportOptions transportOptions;
|
||||
transportOptions.SslVerifyPeer = false;
|
||||
m_transport = std::make_shared<Azure::Core::Http::CurlTransport>(transportOptions);
|
||||
}
|
||||
#endif
|
||||
m_httpMethod
|
||||
= Azure::Core::Http::HttpMethod(m_options.GetMandatoryOption<std::string>("Method"));
|
||||
|
||||
if (m_httpMethod == Azure::Core::Http::HttpMethod::Get)
|
||||
{
|
||||
m_target = GetTestProxy() + "/Admin/isAlive";
|
||||
}
|
||||
else if (m_httpMethod == Azure::Core::Http::HttpMethod::Post)
|
||||
{
|
||||
m_target = GetTestProxy() + "/Admin/setRecordingOptions";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Use HTTPTransportTest to call test proxy endpoint.
|
||||
*
|
||||
*/
|
||||
void Run(Azure::Core::Context const&) override
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_httpMethod == Azure::Core::Http::HttpMethod::Get)
|
||||
{
|
||||
GetRequest();
|
||||
}
|
||||
else if (m_httpMethod == Azure::Core::Http::HttpMethod::Post)
|
||||
{
|
||||
PostRequest();
|
||||
}
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
// don't print exceptions, they are happening at each request, this is the point of the test
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Define the test options for the test.
|
||||
*
|
||||
* @return The list of test options.
|
||||
*/
|
||||
std::vector<Azure::Perf::TestOption> GetTestOptions() override
|
||||
{
|
||||
return {
|
||||
{"Method", {"--method"}, "The HTTP method e.g. GET, POST etc.", 1, true},
|
||||
{"Transport", {"--transport"}, "The HTTP Transport curl/winhttp.", 1, true}};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the static Test Metadata for the test.
|
||||
*
|
||||
* @return Azure::Perf::TestMetadata describing the test.
|
||||
*/
|
||||
static Azure::Perf::TestMetadata GetTestMetadata()
|
||||
{
|
||||
return {
|
||||
"HTTPTransportTest",
|
||||
"Measures HTTP transport performance",
|
||||
[](Azure::Perf::TestOptions options) {
|
||||
return std::make_unique<Azure::Core::Test::HTTPTransportTest>(options);
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace Azure::Core::Test
|
||||
@ -1,6 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "azure/core/test/http_transport_test.hpp"
|
||||
#include "azure/core/test/nullable_test.hpp"
|
||||
#include "azure/core/test/uuid_test.hpp"
|
||||
|
||||
@ -13,6 +14,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// Create the test list
|
||||
std::vector<Azure::Perf::TestMetadata> tests{
|
||||
Azure::Core::Test::HTTPTransportTest::GetTestMetadata(),
|
||||
Azure::Core::Test::NullableTest::GetTestMetadata(),
|
||||
Azure::Core::Test::UuidTest::GetTestMetadata()};
|
||||
|
||||
|
||||
@ -170,5 +170,10 @@ namespace Azure { namespace Perf {
|
||||
ConfigureClientOptions(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the test proxy.
|
||||
*/
|
||||
std::string GetTestProxy() const { return m_proxy; }
|
||||
};
|
||||
}} // namespace Azure::Perf
|
||||
|
||||
Loading…
Reference in New Issue
Block a user