update tests from core to run together (#1818)

This commit is contained in:
Victor Vazquez 2021-03-09 14:42:15 -08:00 committed by GitHub
parent dd3c79c9b4
commit 931cb76e82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 25 deletions

View File

@ -82,9 +82,21 @@ target_include_directories (azure-core-test PRIVATE $<BUILD_INTERFACE:${CMAKE_CU
target_link_libraries(azure-core-test PRIVATE azure-core gtest gmock)
## Global context test
add_executable (
azure-core-global-context-test
global_context.cpp
)
target_link_libraries(azure-core-global-context-test PRIVATE azure-core gtest_main)
# gtest_discover_tests will scan the test from azure-core-test and call add_test
# for each test to ctest. This enables `ctest -r` to run specific tests directly.
gtest_discover_tests(azure-core-test
TEST_PREFIX azure-core.
NO_PRETTY_TYPES
NO_PRETTY_VALUES)
gtest_discover_tests(azure-core-global-context-test
TEST_PREFIX azure-core-global-context.
NO_PRETTY_TYPES
NO_PRETTY_VALUES)

View File

@ -81,31 +81,6 @@ TEST(Context, BasicChar)
EXPECT_TRUE(kind == ContextValue::ContextValueType::StdString);
}
TEST(Context, ApplicationContext)
{
Context appContext = GetApplicationContext();
EXPECT_FALSE(appContext.HasKey("Key"));
EXPECT_FALSE(appContext.HasKey("key"));
EXPECT_FALSE(appContext.HasKey("Value"));
EXPECT_FALSE(appContext.HasKey("value"));
EXPECT_FALSE(appContext.HasKey("1"));
EXPECT_FALSE(appContext.HasKey(""));
auto duration = std::chrono::milliseconds(250);
EXPECT_FALSE(appContext.IsCancelled());
std::this_thread::sleep_for(duration);
EXPECT_FALSE(appContext.IsCancelled());
appContext.Cancel();
EXPECT_TRUE(appContext.IsCancelled());
// AppContext2 is the same context as AppContext
// The context should be cancelled
Context appContext2 = GetApplicationContext();
EXPECT_TRUE(appContext.IsCancelled());
}
TEST(Context, IsCancelled)
{
auto duration = std::chrono::milliseconds(250);

View File

@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief This test is expected to be in one binary alone because it checks the cancellation of the
* global application context. Any other test using the global context after this test would fail.
*
* Do not add more tests to this file unless the tests will not use the global context.
*
*/
#include <gtest/gtest.h>
#include <azure/core/context.hpp>
#include <chrono>
#include <string>
#include <thread>
using namespace Azure::Core;
TEST(Context, ApplicationContext)
{
Context appContext = GetApplicationContext();
EXPECT_FALSE(appContext.HasKey("Key"));
EXPECT_FALSE(appContext.HasKey("key"));
EXPECT_FALSE(appContext.HasKey("Value"));
EXPECT_FALSE(appContext.HasKey("value"));
EXPECT_FALSE(appContext.HasKey("1"));
EXPECT_FALSE(appContext.HasKey(""));
auto duration = std::chrono::milliseconds(250);
EXPECT_FALSE(appContext.IsCancelled());
std::this_thread::sleep_for(duration);
EXPECT_FALSE(appContext.IsCancelled());
appContext.Cancel();
EXPECT_TRUE(appContext.IsCancelled());
// AppContext2 is the same context as AppContext
// The context should be cancelled
Context appContext2 = GetApplicationContext();
EXPECT_TRUE(appContext2.IsCancelled());
}

View File

@ -146,6 +146,8 @@ TEST(Policy, RetryPolicyCounter)
using namespace Azure::Core;
using namespace Azure::Core::Http;
using namespace Azure::Core::Http::Internal;
// Clean the validation global state
retryCounterState = 0;
// Check when there's no info about retry on the context
auto initialContext = GetApplicationContext();
@ -154,6 +156,8 @@ TEST(Policy, RetryPolicyCounter)
// Pipeline with retry test
std::vector<std::unique_ptr<HttpPolicy>> policies;
RetryOptions opt;
// Make retry policy not to take too much time for this test
opt.RetryDelay = std::chrono::milliseconds(10);
policies.push_back(std::make_unique<RetryPolicy>(opt));
policies.push_back(std::make_unique<TestRetryPolicySharedState>());
policies.push_back(std::make_unique<SuccessAfter>());
@ -168,6 +172,8 @@ TEST(Policy, RetryPolicyRetryCycle)
using namespace Azure::Core;
using namespace Azure::Core::Http;
using namespace Azure::Core::Http::Internal;
// Clean the validation global state
retryCounterState = 0;
// Pipeline with retry test
std::vector<std::unique_ptr<HttpPolicy>> policies;