Skip to content

Commit

Permalink
Fix some infrequent test case failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinming-Hu authored and vinjiang committed Sep 26, 2019
1 parent 60c5b9b commit ee3a3f7
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Microsoft.WindowsAzure.Storage/tests/blob_streams_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ SUITE(Blob)

TEST_FIXTURE(block_blob_test_base, block_blob_write_stream_maximum_execution_time)
{
std::chrono::milliseconds duration(300);
std::chrono::seconds duration(10);

azure::storage::blob_request_options options;
options.set_maximum_execution_time(duration);
Expand Down
17 changes: 2 additions & 15 deletions Microsoft.WindowsAzure.Storage/tests/blob_test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@
#include "wascore/util.h"


void blob_service_test_base::fill_buffer(std::vector<uint8_t>& buffer)
{
fill_buffer(buffer, 0, buffer.size());
}

void blob_service_test_base::fill_buffer(std::vector<uint8_t>& buffer, size_t offset, size_t count)
{
std::generate_n(buffer.begin() + offset, count, []() -> uint8_t
{
return uint8_t(std::rand());
});
}

utility::string_t blob_service_test_base::fill_buffer_and_get_md5(std::vector<uint8_t>& buffer)
{
return fill_buffer_and_get_md5(buffer, 0, buffer.size());
Expand Down Expand Up @@ -72,8 +59,8 @@ utility::string_t blob_service_test_base::get_random_container_name(size_t lengt
name.resize(length);
std::generate_n(name.begin(), length, [] () -> utility::char_t
{
const utility::char_t possible_chars[] = { _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890") };
return possible_chars[std::rand() % (sizeof(possible_chars) / sizeof(utility::char_t) - 1)];
const utility::string_t possible_chars = _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890");
return possible_chars[get_random_int32() % possible_chars.length()];
});

return azure::storage::core::convert_to_string(utility::datetime::utc_now().to_interval()) + name;
Expand Down
2 changes: 0 additions & 2 deletions Microsoft.WindowsAzure.Storage/tests/blob_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class blob_service_test_base : public test_base
protected:

static web::http::uri defiddler(const web::http::uri& uri);
static void fill_buffer(std::vector<uint8_t>& buffer);
static void fill_buffer(std::vector<uint8_t>& buffer, size_t offset, size_t count);
static utility::string_t fill_buffer_and_get_md5(std::vector<uint8_t>& buffer);
static utility::string_t fill_buffer_and_get_crc64(std::vector<uint8_t>& buffer);
static utility::string_t fill_buffer_and_get_md5(std::vector<uint8_t>& buffer, size_t offset, size_t count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ SUITE(Blob)
try
{
auto task_result = m_blob.create_or_replace_async(azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
cancel_token_src.cancel();
task_result.get();
}
Expand Down
11 changes: 6 additions & 5 deletions Microsoft.WindowsAzure.Storage/tests/cloud_blob_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ azure::storage::operation_context blob_test_base::upload_and_download(azure::sto
std::vector<uint8_t> buffer;
buffer.resize(buffer_size);
size_t target_blob_size = blob_size == 0 ? buffer_size - buffer_offset : blob_size;
auto md5 = fill_buffer_and_get_md5(buffer, buffer_offset, target_blob_size);
auto md5 = fill_buffer_and_get_md5(buffer, buffer_offset, std::min(target_blob_size, buffer.size() - buffer_offset));

concurrency::streams::istream stream;
if (use_seekable_stream)
Expand Down Expand Up @@ -794,7 +794,7 @@ SUITE(Blob)
for (size_t i = 0; i < 2; ++i)
{
auto file_name = this->get_random_string();
auto share = test_config::instance().account().create_cloud_file_client().get_share_reference(_XPLATSTR("testshare"));
auto share = test_config::instance().account().create_cloud_file_client().get_share_reference(_XPLATSTR("testshare") + get_random_string());
share.create_if_not_exists();
auto source = share.get_root_directory_reference().get_file_reference(file_name);
source.upload_text(_XPLATSTR("1"), azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);
Expand All @@ -812,6 +812,7 @@ SUITE(Blob)
CHECK(wait_for_copy(dest));
CHECK_THROW(dest.abort_copy(copy_id, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception);
CHECK_EQUAL(web::http::status_codes::Conflict, m_context.request_results().back().http_status_code());
share.delete_share();
}
}

Expand Down Expand Up @@ -892,7 +893,7 @@ SUITE(Blob)
azure::storage::operation_context context;
concurrency::streams::container_buffer<std::vector<uint8_t>> download_buffer;

utility::size64_t actual_offset = rand() % 255 + 1;
utility::size64_t actual_offset = get_random_int32() % 255 + 1;
utility::size64_t actual_length = target_length - actual_offset;
blob.download_range_to_stream(download_buffer.create_ostream(), actual_offset, actual_length, azure::storage::access_condition(), option, context);

Expand Down Expand Up @@ -920,7 +921,7 @@ SUITE(Blob)
azure::storage::operation_context context;
concurrency::streams::container_buffer<std::vector<uint8_t>> download_buffer;

utility::size64_t actual_offset = rand() % 255 + 1;
utility::size64_t actual_offset = get_random_int32() % 255 + 1;
utility::size64_t actual_length = target_length - actual_offset;
blob.download_range_to_stream(download_buffer.create_ostream(), actual_offset, std::numeric_limits<utility::size64_t>::max(), azure::storage::access_condition(), option, context);

Expand Down Expand Up @@ -954,7 +955,7 @@ SUITE(Blob)
azure::storage::operation_context context;
concurrency::streams::container_buffer<std::vector<uint8_t>> download_buffer;

utility::size64_t actual_offset = rand() % 255 + 1;
utility::size64_t actual_offset = get_random_int32() % 255 + 1;
utility::size64_t actual_length = target_length - actual_offset;
blob.download_range_to_stream(download_buffer.create_ostream(), actual_offset, actual_length * 2, azure::storage::access_condition(), option, context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ SUITE(Blob)
try
{
auto task_result = m_blob.delete_blob_if_exists_async(azure::storage::delete_snapshots_option::include_snapshots, azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
cancel_token_src.cancel();
task_result.get();
}
Expand Down Expand Up @@ -1610,7 +1610,7 @@ SUITE(Blob)

{
auto options = azure::storage::blob_request_options();
options.set_maximum_execution_time(std::chrono::milliseconds(10000));
options.set_maximum_execution_time(std::chrono::seconds(20));

std::string ex_msg;

Expand Down Expand Up @@ -1735,7 +1735,7 @@ SUITE(Blob)
auto task_result = m_blob.open_write_async(azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
auto os = task_result.get();
os.streambuf().putn_nocopy(buffer.data(), buffer.size()).wait();
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
cancel_token_src.cancel();
os.close().get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SUITE(File)

TEST_FIXTURE(file_share_test_base, share_create_delete_with_quotas)
{
size_t quota = rand() % 5120 + 1;
size_t quota = get_random_int32() % 5120 + 1;

CHECK(!m_share.exists(azure::storage::file_request_options(), m_context));
CHECK(!m_share.delete_share_if_exists(azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context));
Expand Down
27 changes: 10 additions & 17 deletions Microsoft.WindowsAzure.Storage/tests/cloud_file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ SUITE(File)
for (size_t i = 0; i < 2; ++i)
{
auto blob_name = this->get_random_string();
auto container = test_config::instance().account().create_cloud_blob_client().get_container_reference(_XPLATSTR("container"));
auto container = test_config::instance().account().create_cloud_blob_client().get_container_reference(_XPLATSTR("container") + get_random_string());
container.create_if_not_exists();

auto source = container.get_block_blob_reference(blob_name);
Expand All @@ -411,6 +411,8 @@ SUITE(File)
CHECK(wait_for_copy(dest));
CHECK_THROW(dest.abort_copy(copy_id, azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context), azure::storage::storage_exception);
CHECK_EQUAL(web::http::status_codes::Conflict, m_context.request_results().back().http_status_code());

container.delete_container();
}
}

Expand Down Expand Up @@ -724,18 +726,15 @@ SUITE(File)
option.set_parallelism_factor(2);
std::vector<uint8_t> data;
data.resize(target_length);
for (size_t i = 0; i < target_length; ++i)
{
data[i] = i % 255;
}
fill_buffer(data);
concurrency::streams::container_buffer<std::vector<uint8_t>> upload_buffer(data);
file.upload_from_stream(upload_buffer.create_istream(), azure::storage::file_access_condition(), option, m_context);

// download target file in parallel.
azure::storage::operation_context context;
concurrency::streams::container_buffer<std::vector<uint8_t>> download_buffer;

utility::size64_t actual_offset = rand() % 255 + 1;
utility::size64_t actual_offset = get_random_int32() % 255 + 1;
utility::size64_t actual_length = target_length - actual_offset;
file.download_range_to_stream(download_buffer.create_ostream(), actual_offset, actual_length, azure::storage::file_access_condition(), option, context);

Expand All @@ -755,18 +754,15 @@ SUITE(File)
option.set_parallelism_factor(2);
std::vector<uint8_t> data;
data.resize(target_length);
for (size_t i = 0; i < target_length; ++i)
{
data[i] = i % 255;
}
fill_buffer(data);
concurrency::streams::container_buffer<std::vector<uint8_t>> upload_buffer(data);
file.upload_from_stream(upload_buffer.create_istream(), azure::storage::file_access_condition(), option, m_context);

// download target file in parallel.
azure::storage::operation_context context;
concurrency::streams::container_buffer<std::vector<uint8_t>> download_buffer;

utility::size64_t actual_offset = rand() % 255 + 1;
utility::size64_t actual_offset = get_random_int32() % 255 + 1;
utility::size64_t actual_length = target_length - actual_offset;
file.download_range_to_stream(download_buffer.create_ostream(), actual_offset, std::numeric_limits<utility::size64_t>::max(), azure::storage::file_access_condition(), option, context);

Expand All @@ -792,18 +788,15 @@ SUITE(File)
option.set_parallelism_factor(10);
std::vector<uint8_t> data;
data.resize(target_length);
for (size_t i = 0; i < target_length; ++i)
{
data[i] = i % 255;
}
fill_buffer(data);
concurrency::streams::container_buffer<std::vector<uint8_t>> upload_buffer(data);
file.upload_from_stream(upload_buffer.create_istream(), azure::storage::file_access_condition(), option, m_context);

// download target file in parallel.
azure::storage::operation_context context;
concurrency::streams::container_buffer<std::vector<uint8_t>> download_buffer;

utility::size64_t actual_offset = rand() % 255 + 1;
utility::size64_t actual_offset = get_random_int32() % 255 + 1;
utility::size64_t actual_length = target_length - actual_offset;
file.download_range_to_stream(download_buffer.create_ostream(), actual_offset, actual_length * 2, azure::storage::file_access_condition(), option, context);

Expand Down Expand Up @@ -887,4 +880,4 @@ SUITE(File)
check_parallelism(context, 1);
CHECK(file.properties().size() == target_length);
}
}
}
4 changes: 2 additions & 2 deletions Microsoft.WindowsAzure.Storage/tests/cloud_page_blob_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ SUITE(Blob)
try
{
auto task_result = m_blob.create_async(1024, azure::storage::premium_blob_tier::unknown, 0, azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
cancel_token_src.cancel();
task_result.get();
}
Expand Down Expand Up @@ -1528,7 +1528,7 @@ SUITE(Blob)
auto task_result = m_blob.open_write_async(azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
auto os = task_result.get();
os.streambuf().putn_nocopy(buffer.data(), buffer.size()).wait();
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
cancel_token_src.cancel();
os.close().get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include "stdafx.h"

#include <vector>
#include <future>

#include "test_base.h"
#include "check_macros.h"
#include "was/storage_account.h"
Expand Down Expand Up @@ -906,22 +909,31 @@ SUITE(Core)

TEST_FIXTURE(test_base, account_sas_permission)
{
auto account = test_config::instance().account();
auto check_account_permission = [](int i) {
auto account = test_config::instance().account();

azure::storage::account_shared_access_policy policy;
policy.set_expiry(utility::datetime::utc_now() + utility::datetime::from_minutes(90));
policy.set_address_or_range(azure::storage::shared_access_policy::ip_address_or_range(_XPLATSTR("0.0.0.0"), _XPLATSTR("255.255.255.255")));
policy.set_protocol(azure::storage::account_shared_access_policy::protocols::https_or_http);
policy.set_service_type((azure::storage::account_shared_access_policy::service_types)0xF);
policy.set_resource_type((azure::storage::account_shared_access_policy::resource_types)0x7);
azure::storage::account_shared_access_policy policy;
policy.set_expiry(utility::datetime::utc_now() + utility::datetime::from_minutes(90));
policy.set_address_or_range(azure::storage::shared_access_policy::ip_address_or_range(_XPLATSTR("0.0.0.0"), _XPLATSTR("255.255.255.255")));
policy.set_protocol(azure::storage::account_shared_access_policy::protocols::https_or_http);
policy.set_service_type((azure::storage::account_shared_access_policy::service_types)0xF);
policy.set_resource_type((azure::storage::account_shared_access_policy::resource_types)0x7);

for (int i = 1; i < 0x100; i++)
{
policy.set_permissions((uint8_t)i);
check_account_sas_permission_blob(account, policy);
check_account_sas_permission_queue(account, policy);
check_account_sas_permission_table(account, policy);
check_account_sas_permission_file(account, policy);
};

std::vector<std::future<void>> results;
for (int i = 1; i < 0x100; ++i)
{
results.emplace_back(std::async(check_account_permission, i));
}
for (const auto& r : results)
{
r.wait();
}
}

Expand Down
6 changes: 3 additions & 3 deletions Microsoft.WindowsAzure.Storage/tests/file_test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ utility::string_t file_service_test_base::get_random_share_name(size_t length)
name.resize(length);
std::generate_n(name.begin(), length, []() -> utility::char_t
{
const utility::char_t possible_chars[] = { _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890") };
return possible_chars[std::rand() % (sizeof(possible_chars) / sizeof(utility::char_t) - 1)];
const utility::string_t possible_chars = _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890");
return possible_chars[get_random_int32() % possible_chars.length()];
});

return azure::storage::core::convert_to_string(utility::datetime::utc_now().to_interval()) + name;
Expand Down Expand Up @@ -212,4 +212,4 @@ void file_share_test_base::check_access(const utility::string_t& sas_token, uint
{
CHECK_THROW(file.delete_file(azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context), azure::storage::storage_exception);
}
}
}
Loading

0 comments on commit ee3a3f7

Please sign in to comment.