From 931cb76e828a1d7ea9102bcf304615acf9133167 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Tue, 9 Mar 2021 14:42:15 -0800 Subject: [PATCH] update tests from core to run together (#1818) --- sdk/core/azure-core/test/ut/CMakeLists.txt | 12 +++++ sdk/core/azure-core/test/ut/context.cpp | 25 ---------- .../azure-core/test/ut/global_context.cpp | 46 +++++++++++++++++++ sdk/core/azure-core/test/ut/policy.cpp | 6 +++ 4 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 sdk/core/azure-core/test/ut/global_context.cpp diff --git a/sdk/core/azure-core/test/ut/CMakeLists.txt b/sdk/core/azure-core/test/ut/CMakeLists.txt index 66e6963c3..6b07936ac 100644 --- a/sdk/core/azure-core/test/ut/CMakeLists.txt +++ b/sdk/core/azure-core/test/ut/CMakeLists.txt @@ -82,9 +82,21 @@ target_include_directories (azure-core-test PRIVATE $ + +#include + +#include +#include +#include + +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()); +} diff --git a/sdk/core/azure-core/test/ut/policy.cpp b/sdk/core/azure-core/test/ut/policy.cpp index cf5d888bc..f7ee4db18 100644 --- a/sdk/core/azure-core/test/ut/policy.cpp +++ b/sdk/core/azure-core/test/ut/policy.cpp @@ -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> 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(opt)); policies.push_back(std::make_unique()); policies.push_back(std::make_unique()); @@ -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> policies;