Skip to content
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

Add parallel platform uuid test #2790

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all 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
41 changes: 36 additions & 5 deletions tests/aws-cpp-sdk-core-tests/utils/UUIDTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ TEST_F(UUIDTest, TestPlatformGeneratesUUID)
for(size_t i = 0u; i < 1000u; ++i)
{
UUID uuid = UUID::RandomUUID();
Aws::String uuidStr = uuid;
Aws::String uuidStr = uuid;
ASSERT_EQ(36u, uuidStr.length());
ByteBuffer rawUUID = uuid;
ASSERT_EQ(16u, rawUUID.GetLength());
ASSERT_EQ(0x40u, 0x40u & rawUUID[6]);
ASSERT_EQ(0x80u, 0x80u & rawUUID[8]);

auto iter = generatedUUids.find(uuidStr);
auto endIter = generatedUUids.end();
ASSERT_TRUE( iter == endIter );
auto iter = generatedUUids.find(uuidStr);
auto endIter = generatedUUids.end();
ASSERT_TRUE( iter == endIter );

generatedUUids.insert(uuidStr);
}
}
}

TEST_F(UUIDTest, TestUUIDToStringConversion)
Expand Down Expand Up @@ -112,3 +112,34 @@ TEST_F(UUIDTest, TestPseudoRandomParallelUUID)
ASSERT_EQ(BATCHES * 1000u, generatedAllUUids.size());
}

TEST_F(UUIDTest, TestPlatformRandomParallelUUID)
{
Aws::UnorderedSet<Aws::String> generatedAllUUids;

static const size_t BATCHES = 20;
static const size_t PER_BATCH = 1000u;
Aws::Vector<std::future<Aws::UnorderedSet<Aws::String>>> futures(BATCHES);

for(size_t i = 0; i < BATCHES; ++i)
{
futures[i] = std::async(
[]()
{
Aws::UnorderedSet<Aws::String> generatedUUids;
for(size_t i = 0u; i < PER_BATCH; ++i)
{
generatedUUids.insert(StringUtils::ToLower(Aws::String(UUID::RandomUUID()).c_str()));
}

return generatedUUids;
});
}

for(size_t i = 0; i < BATCHES; ++i)
{
Aws::UnorderedSet<Aws::String> batch = futures[i].get();
ASSERT_EQ(PER_BATCH, batch.size());
generatedAllUUids.insert(batch.begin(), batch.end());
}
ASSERT_EQ(BATCHES * PER_BATCH, generatedAllUUids.size());
}
Loading