Skip to content

Improved discoverability of tests; handle exceptions thrown during test execution #4021

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

Merged
merged 15 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
84 changes: 83 additions & 1 deletion CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DINSTALL_GTEST=OFF -DBUILD_TESTING=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_SAMPLES=ON -DBUILD_PERFORMANCE_TESTS=ON",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": [
Expand All @@ -246,6 +246,88 @@
"value": "x64-windows-static",
"type": "STRING"
},
{
"name": "INSTALL_GTEST",
"value": "False",
"type": "BOOL"
},
{
"name": "BUILD_TESTING",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_SAMPLES",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_PERFORMANCE_TESTS",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_TRANSPORT_WINHTTP",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_TRANSPORT_CURL",
"value": "True",
"type": "BOOL"
},
{
"name": "MSVC_USE_STATIC_CRT",
"value": "True",
"type": "BOOL"
}
]
},
{
"name": "x64-ReleaseWithPerfTest",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": [
{
"name": "VCPKG_TARGET_TRIPLET",
"value": "x64-windows-static",
"type": "STRING"
},
{
"name": "INSTALL_GTEST",
"value": "False",
"type": "BOOL"
},
{
"name": "BUILD_TESTING",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_SAMPLES",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_PERFORMANCE_TESTS",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_TRANSPORT_WINHTTP",
"value": "True",
"type": "BOOL"
},
{
"name": "BUILD_TRANSPORT_CURL",
"value": "True",
"type": "BOOL"
},
{
"name": "MSVC_USE_STATIC_CRT",
"value": "True",
Expand Down
1 change: 1 addition & 0 deletions sdk/core/perf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ usage: azure-perf-test testName [options]
>Note: You can use the option `-h` to print out the available options for a test name.

The next options can be used for any test:

| Option | Activators | Description | Default | Example |
| ---------- | --- | ---| ---| --- |
| Duration | -d, --duration | Duration of the test in seconds | 10 | -d 5
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/perf/inc/azure/perf/argagg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ inline fmt_ostream::~fmt_ostream() { output << fmt_string(this->str()); }

inline std::string lstrip(const std::string& text)
{
auto result = text;
std::string result = text;

result.erase(result.begin(), std::find_if(result.begin(), result.end(), [](int ch) {
return !std::isspace(ch);
Expand All @@ -1447,7 +1447,7 @@ inline std::string lstrip(const std::string& text)

inline std::string rstrip(const std::string& text)
{
auto result = text;
std::string result = text;

result.erase(
std::find_if(result.rbegin(), result.rend(), [](int ch) { return !std::isspace(ch); }).base(),
Expand Down
132 changes: 70 additions & 62 deletions sdk/core/perf/src/base_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ProxyPolicy final : public HttpPolicy {
ProxyPolicy(ProxyPolicy const& other) : ProxyPolicy{other.m_testContext} {}

// move
ProxyPolicy(ProxyPolicy&& other) : m_testContext{other.m_testContext} {}
ProxyPolicy(ProxyPolicy&& other) noexcept : m_testContext{other.m_testContext} {}

std::unique_ptr<RawResponse> Send(
Request& request,
Expand Down Expand Up @@ -138,72 +138,80 @@ namespace Azure { namespace Perf {
void BaseTest::PostSetUp()
{

if (!m_proxy.empty())
try
{
Azure::Core::_internal::ClientOptions clientOp;
clientOp.Retry.MaxRetries = 0;
ConfigureInsecureConnection(clientOp);
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> policiesOp;
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> policiesRe;
Azure::Core::Http::_internal::HttpPipeline pipeline(
clientOp, "PerfFw", "na", std::move(policiesRe), std::move(policiesOp));
Azure::Core::Context ctx;

// Make one call to Run() before starting recording, to avoid capturing one-time setup
// like authorization requests.
this->Run(ctx);

// Send start-record call
{
Azure::Core::Url startRecordReq(m_proxy);
startRecordReq.AppendPath("record");
startRecordReq.AppendPath("start");
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Post, startRecordReq);
auto response = pipeline.Send(request, ctx);

auto const& headers = response->GetHeaders();
auto findHeader = std::find_if(
headers.begin(),
headers.end(),
[](std::pair<std::string const&, std::string const&> h) {
return h.first == "x-recording-id";
});
m_recordId = findHeader->second;
}

// Record one call to re-use response on all test runs
this->Run(ctx);

// Stop recording
if (!m_proxy.empty())
{
Azure::Core::Url stopRecordReq(m_proxy);
stopRecordReq.AppendPath("record");
stopRecordReq.AppendPath("stop");
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Post, stopRecordReq);
request.SetHeader("x-recording-id", m_recordId);
pipeline.Send(request, ctx);
}

// Start playback
{
Azure::Core::Url startPlayback(m_proxy);
startPlayback.AppendPath("playback");
startPlayback.AppendPath("start");
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Post, startPlayback);
request.SetHeader("x-recording-id", m_recordId);
auto response = pipeline.Send(request, ctx);

auto const& headers = response->GetHeaders();
auto findHeader = std::find_if(
headers.begin(),
headers.end(),
[](std::pair<std::string const&, std::string const&> h) {
return h.first == "x-recording-id";
});
m_recordId = findHeader->second;
m_isPlayBackMode = true;
Azure::Core::_internal::ClientOptions clientOp;
clientOp.Retry.MaxRetries = 0;
ConfigureInsecureConnection(clientOp);
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> policiesOp;
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> policiesRe;
Azure::Core::Http::_internal::HttpPipeline pipeline(
clientOp, "PerfFw", "na", std::move(policiesRe), std::move(policiesOp));
Azure::Core::Context ctx;

// Make one call to Run() before starting recording, to avoid capturing one-time setup
// like authorization requests.
this->Run(ctx);

// Send start-record call
{
Azure::Core::Url startRecordReq(m_proxy);
startRecordReq.AppendPath("record");
startRecordReq.AppendPath("start");
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Post, startRecordReq);
auto response = pipeline.Send(request, ctx);

auto const& headers = response->GetHeaders();
auto findHeader = std::find_if(
headers.begin(),
headers.end(),
[](std::pair<std::string const&, std::string const&> h) {
return h.first == "x-recording-id";
});
m_recordId = findHeader->second;
}

// Record one call to re-use response on all test runs
this->Run(ctx);

// Stop recording
{
Azure::Core::Url stopRecordReq(m_proxy);
stopRecordReq.AppendPath("record");
stopRecordReq.AppendPath("stop");
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Post, stopRecordReq);
request.SetHeader("x-recording-id", m_recordId);
pipeline.Send(request, ctx);
}

// Start playback
{
Azure::Core::Url startPlayback(m_proxy);
startPlayback.AppendPath("playback");
startPlayback.AppendPath("start");
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Post, startPlayback);
request.SetHeader("x-recording-id", m_recordId);
auto response = pipeline.Send(request, ctx);

auto const& headers = response->GetHeaders();
auto findHeader = std::find_if(
headers.begin(),
headers.end(),
[](std::pair<std::string const&, std::string const&> h) {
return h.first == "x-recording-id";
});
m_recordId = findHeader->second;
m_isPlayBackMode = true;
}
}
}
catch (std::exception const& e)
{
std::cout << "Exception thrown after setup: " << e.what() << std::endl;
}
}

void BaseTest::PreCleanUp()
Expand Down
Loading