Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit ee3a3f7

Browse files
Jinming-Huvinjiang
authored andcommitted
Fix some infrequent test case failures.
1 parent 60c5b9b commit ee3a3f7

16 files changed

+281
-142
lines changed

Microsoft.WindowsAzure.Storage/tests/blob_streams_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ SUITE(Blob)
620620

621621
TEST_FIXTURE(block_blob_test_base, block_blob_write_stream_maximum_execution_time)
622622
{
623-
std::chrono::milliseconds duration(300);
623+
std::chrono::seconds duration(10);
624624

625625
azure::storage::blob_request_options options;
626626
options.set_maximum_execution_time(duration);

Microsoft.WindowsAzure.Storage/tests/blob_test_base.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@
2323
#include "wascore/util.h"
2424

2525

26-
void blob_service_test_base::fill_buffer(std::vector<uint8_t>& buffer)
27-
{
28-
fill_buffer(buffer, 0, buffer.size());
29-
}
30-
31-
void blob_service_test_base::fill_buffer(std::vector<uint8_t>& buffer, size_t offset, size_t count)
32-
{
33-
std::generate_n(buffer.begin() + offset, count, []() -> uint8_t
34-
{
35-
return uint8_t(std::rand());
36-
});
37-
}
38-
3926
utility::string_t blob_service_test_base::fill_buffer_and_get_md5(std::vector<uint8_t>& buffer)
4027
{
4128
return fill_buffer_and_get_md5(buffer, 0, buffer.size());
@@ -72,8 +59,8 @@ utility::string_t blob_service_test_base::get_random_container_name(size_t lengt
7259
name.resize(length);
7360
std::generate_n(name.begin(), length, [] () -> utility::char_t
7461
{
75-
const utility::char_t possible_chars[] = { _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890") };
76-
return possible_chars[std::rand() % (sizeof(possible_chars) / sizeof(utility::char_t) - 1)];
62+
const utility::string_t possible_chars = _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890");
63+
return possible_chars[get_random_int32() % possible_chars.length()];
7764
});
7865

7966
return azure::storage::core::convert_to_string(utility::datetime::utc_now().to_interval()) + name;

Microsoft.WindowsAzure.Storage/tests/blob_test_base.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class blob_service_test_base : public test_base
4747
protected:
4848

4949
static web::http::uri defiddler(const web::http::uri& uri);
50-
static void fill_buffer(std::vector<uint8_t>& buffer);
51-
static void fill_buffer(std::vector<uint8_t>& buffer, size_t offset, size_t count);
5250
static utility::string_t fill_buffer_and_get_md5(std::vector<uint8_t>& buffer);
5351
static utility::string_t fill_buffer_and_get_crc64(std::vector<uint8_t>& buffer);
5452
static utility::string_t fill_buffer_and_get_md5(std::vector<uint8_t>& buffer, size_t offset, size_t count);

Microsoft.WindowsAzure.Storage/tests/cloud_append_blob_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ SUITE(Blob)
874874
try
875875
{
876876
auto task_result = m_blob.create_or_replace_async(azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
877-
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
877+
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
878878
cancel_token_src.cancel();
879879
task_result.get();
880880
}

Microsoft.WindowsAzure.Storage/tests/cloud_blob_test.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ azure::storage::operation_context blob_test_base::upload_and_download(azure::sto
5454
std::vector<uint8_t> buffer;
5555
buffer.resize(buffer_size);
5656
size_t target_blob_size = blob_size == 0 ? buffer_size - buffer_offset : blob_size;
57-
auto md5 = fill_buffer_and_get_md5(buffer, buffer_offset, target_blob_size);
57+
auto md5 = fill_buffer_and_get_md5(buffer, buffer_offset, std::min(target_blob_size, buffer.size() - buffer_offset));
5858

5959
concurrency::streams::istream stream;
6060
if (use_seekable_stream)
@@ -794,7 +794,7 @@ SUITE(Blob)
794794
for (size_t i = 0; i < 2; ++i)
795795
{
796796
auto file_name = this->get_random_string();
797-
auto share = test_config::instance().account().create_cloud_file_client().get_share_reference(_XPLATSTR("testshare"));
797+
auto share = test_config::instance().account().create_cloud_file_client().get_share_reference(_XPLATSTR("testshare") + get_random_string());
798798
share.create_if_not_exists();
799799
auto source = share.get_root_directory_reference().get_file_reference(file_name);
800800
source.upload_text(_XPLATSTR("1"), azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);
@@ -812,6 +812,7 @@ SUITE(Blob)
812812
CHECK(wait_for_copy(dest));
813813
CHECK_THROW(dest.abort_copy(copy_id, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception);
814814
CHECK_EQUAL(web::http::status_codes::Conflict, m_context.request_results().back().http_status_code());
815+
share.delete_share();
815816
}
816817
}
817818

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

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

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

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

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

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

Microsoft.WindowsAzure.Storage/tests/cloud_block_blob_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ SUITE(Blob)
13811381
try
13821382
{
13831383
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());
1384-
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
1384+
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
13851385
cancel_token_src.cancel();
13861386
task_result.get();
13871387
}
@@ -1610,7 +1610,7 @@ SUITE(Blob)
16101610

16111611
{
16121612
auto options = azure::storage::blob_request_options();
1613-
options.set_maximum_execution_time(std::chrono::milliseconds(10000));
1613+
options.set_maximum_execution_time(std::chrono::seconds(20));
16141614

16151615
std::string ex_msg;
16161616

@@ -1735,7 +1735,7 @@ SUITE(Blob)
17351735
auto task_result = m_blob.open_write_async(azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
17361736
auto os = task_result.get();
17371737
os.streambuf().putn_nocopy(buffer.data(), buffer.size()).wait();
1738-
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
1738+
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
17391739
cancel_token_src.cancel();
17401740
os.close().get();
17411741
}

Microsoft.WindowsAzure.Storage/tests/cloud_file_share_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SUITE(File)
4545

4646
TEST_FIXTURE(file_share_test_base, share_create_delete_with_quotas)
4747
{
48-
size_t quota = rand() % 5120 + 1;
48+
size_t quota = get_random_int32() % 5120 + 1;
4949

5050
CHECK(!m_share.exists(azure::storage::file_request_options(), m_context));
5151
CHECK(!m_share.delete_share_if_exists(azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context));

Microsoft.WindowsAzure.Storage/tests/cloud_file_test.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ SUITE(File)
390390
for (size_t i = 0; i < 2; ++i)
391391
{
392392
auto blob_name = this->get_random_string();
393-
auto container = test_config::instance().account().create_cloud_blob_client().get_container_reference(_XPLATSTR("container"));
393+
auto container = test_config::instance().account().create_cloud_blob_client().get_container_reference(_XPLATSTR("container") + get_random_string());
394394
container.create_if_not_exists();
395395

396396
auto source = container.get_block_blob_reference(blob_name);
@@ -411,6 +411,8 @@ SUITE(File)
411411
CHECK(wait_for_copy(dest));
412412
CHECK_THROW(dest.abort_copy(copy_id, azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context), azure::storage::storage_exception);
413413
CHECK_EQUAL(web::http::status_codes::Conflict, m_context.request_results().back().http_status_code());
414+
415+
container.delete_container();
414416
}
415417
}
416418

@@ -724,18 +726,15 @@ SUITE(File)
724726
option.set_parallelism_factor(2);
725727
std::vector<uint8_t> data;
726728
data.resize(target_length);
727-
for (size_t i = 0; i < target_length; ++i)
728-
{
729-
data[i] = i % 255;
730-
}
729+
fill_buffer(data);
731730
concurrency::streams::container_buffer<std::vector<uint8_t>> upload_buffer(data);
732731
file.upload_from_stream(upload_buffer.create_istream(), azure::storage::file_access_condition(), option, m_context);
733732

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

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

@@ -755,18 +754,15 @@ SUITE(File)
755754
option.set_parallelism_factor(2);
756755
std::vector<uint8_t> data;
757756
data.resize(target_length);
758-
for (size_t i = 0; i < target_length; ++i)
759-
{
760-
data[i] = i % 255;
761-
}
757+
fill_buffer(data);
762758
concurrency::streams::container_buffer<std::vector<uint8_t>> upload_buffer(data);
763759
file.upload_from_stream(upload_buffer.create_istream(), azure::storage::file_access_condition(), option, m_context);
764760

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

769-
utility::size64_t actual_offset = rand() % 255 + 1;
765+
utility::size64_t actual_offset = get_random_int32() % 255 + 1;
770766
utility::size64_t actual_length = target_length - actual_offset;
771767
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);
772768

@@ -792,18 +788,15 @@ SUITE(File)
792788
option.set_parallelism_factor(10);
793789
std::vector<uint8_t> data;
794790
data.resize(target_length);
795-
for (size_t i = 0; i < target_length; ++i)
796-
{
797-
data[i] = i % 255;
798-
}
791+
fill_buffer(data);
799792
concurrency::streams::container_buffer<std::vector<uint8_t>> upload_buffer(data);
800793
file.upload_from_stream(upload_buffer.create_istream(), azure::storage::file_access_condition(), option, m_context);
801794

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

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

@@ -887,4 +880,4 @@ SUITE(File)
887880
check_parallelism(context, 1);
888881
CHECK(file.properties().size() == target_length);
889882
}
890-
}
883+
}

Microsoft.WindowsAzure.Storage/tests/cloud_page_blob_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ SUITE(Blob)
11721172
try
11731173
{
11741174
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());
1175-
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
1175+
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
11761176
cancel_token_src.cancel();
11771177
task_result.get();
11781178
}
@@ -1528,7 +1528,7 @@ SUITE(Blob)
15281528
auto task_result = m_blob.open_write_async(azure::storage::access_condition(), options, m_context, cancel_token_src.get_token());
15291529
auto os = task_result.get();
15301530
os.streambuf().putn_nocopy(buffer.data(), buffer.size()).wait();
1531-
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //sleep for sometime before canceling the request and see result.
1531+
std::this_thread::sleep_for(std::chrono::milliseconds(30)); //sleep for sometime before canceling the request and see result.
15321532
cancel_token_src.cancel();
15331533
os.close().get();
15341534
}

Microsoft.WindowsAzure.Storage/tests/cloud_storage_account_test.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include "stdafx.h"
1919

20+
#include <vector>
21+
#include <future>
22+
2023
#include "test_base.h"
2124
#include "check_macros.h"
2225
#include "was/storage_account.h"
@@ -906,22 +909,31 @@ SUITE(Core)
906909

907910
TEST_FIXTURE(test_base, account_sas_permission)
908911
{
909-
auto account = test_config::instance().account();
912+
auto check_account_permission = [](int i) {
913+
auto account = test_config::instance().account();
910914

911-
azure::storage::account_shared_access_policy policy;
912-
policy.set_expiry(utility::datetime::utc_now() + utility::datetime::from_minutes(90));
913-
policy.set_address_or_range(azure::storage::shared_access_policy::ip_address_or_range(_XPLATSTR("0.0.0.0"), _XPLATSTR("255.255.255.255")));
914-
policy.set_protocol(azure::storage::account_shared_access_policy::protocols::https_or_http);
915-
policy.set_service_type((azure::storage::account_shared_access_policy::service_types)0xF);
916-
policy.set_resource_type((azure::storage::account_shared_access_policy::resource_types)0x7);
915+
azure::storage::account_shared_access_policy policy;
916+
policy.set_expiry(utility::datetime::utc_now() + utility::datetime::from_minutes(90));
917+
policy.set_address_or_range(azure::storage::shared_access_policy::ip_address_or_range(_XPLATSTR("0.0.0.0"), _XPLATSTR("255.255.255.255")));
918+
policy.set_protocol(azure::storage::account_shared_access_policy::protocols::https_or_http);
919+
policy.set_service_type((azure::storage::account_shared_access_policy::service_types)0xF);
920+
policy.set_resource_type((azure::storage::account_shared_access_policy::resource_types)0x7);
917921

918-
for (int i = 1; i < 0x100; i++)
919-
{
920922
policy.set_permissions((uint8_t)i);
921923
check_account_sas_permission_blob(account, policy);
922924
check_account_sas_permission_queue(account, policy);
923925
check_account_sas_permission_table(account, policy);
924926
check_account_sas_permission_file(account, policy);
927+
};
928+
929+
std::vector<std::future<void>> results;
930+
for (int i = 1; i < 0x100; ++i)
931+
{
932+
results.emplace_back(std::async(check_account_permission, i));
933+
}
934+
for (const auto& r : results)
935+
{
936+
r.wait();
925937
}
926938
}
927939

Microsoft.WindowsAzure.Storage/tests/file_test_base.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ utility::string_t file_service_test_base::get_random_share_name(size_t length)
2727
name.resize(length);
2828
std::generate_n(name.begin(), length, []() -> utility::char_t
2929
{
30-
const utility::char_t possible_chars[] = { _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890") };
31-
return possible_chars[std::rand() % (sizeof(possible_chars) / sizeof(utility::char_t) - 1)];
30+
const utility::string_t possible_chars = _XPLATSTR("abcdefghijklmnopqrstuvwxyz1234567890");
31+
return possible_chars[get_random_int32() % possible_chars.length()];
3232
});
3333

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

0 commit comments

Comments
 (0)