Skip to content

Commit

Permalink
Update integration test to verify ID uniqueness of TesTasks in the DB (
Browse files Browse the repository at this point in the history
  • Loading branch information
MattMcL4475 authored Apr 25, 2023
1 parent c70afaa commit 3a2084e
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ public async Task GetItemsAsyncTest()
public async Task Create1mAndQuery1mAsync()
{
const bool createItems = true;
const int itemCount = 1_000_000;

var sw = Stopwatch.StartNew();

if (createItems)
{
var rng = new Random(Guid.NewGuid().GetHashCode());
var states = Enum.GetValues(typeof(Models.TesState));

var items = new List<Models.TesTask>();

for (int i = 0; i < 1_000_000; i++)
for (int i = 0; i < itemCount; i++)
{
var randomState = (Models.TesState)states.GetValue(rng.Next(states.Length));
items.Add(new Models.TesTask
Expand All @@ -134,6 +136,8 @@ public async Task Create1mAndQuery1mAsync()
});
}

Assert.IsTrue(items.Select(i => i.Id).Distinct().Count() == itemCount);

await repository.CreateItemsAsync(items);
Console.WriteLine($"Total seconds to insert {items.Count} items: {sw.Elapsed.TotalSeconds:n2}s");
sw.Restart();
Expand All @@ -142,14 +146,20 @@ public async Task Create1mAndQuery1mAsync()
sw.Restart();
var runningTasks = await repository.GetItemsAsync(c => c.State == Models.TesState.RUNNINGEnum);

// Ensure performance is decent. In manual testing on fast internet, this takes less than 5s typically
Assert.IsTrue(sw.Elapsed.TotalSeconds < 10);
// Ensure performance is decent
Assert.IsTrue(sw.Elapsed.TotalSeconds < 20);
Console.WriteLine($"Retrieved {runningTasks.Count()} in {sw.Elapsed.TotalSeconds:n1}s");
sw.Restart();
var allOtherTasks = await repository.GetItemsAsync(c => c.State != Models.TesState.RUNNINGEnum);
Console.WriteLine($"Retrieved {allOtherTasks.Count()} in {sw.Elapsed.TotalSeconds:n1}s");
Console.WriteLine($"Total running tasks: {runningTasks.Count()}");
Console.WriteLine($"Total other tasks: {allOtherTasks.Count()}");
var distinctRunningTasksIds = runningTasks.Select(i => i.Id).Distinct().Count();
var distinctOtherTaskIds = allOtherTasks.Select(i => i.Id).Distinct().Count();
Console.WriteLine($"uniqueRunningTasksIds: {distinctRunningTasksIds}");
Console.WriteLine($"distinctOtherTaskIds: {distinctOtherTaskIds}");

Assert.IsTrue(distinctRunningTasksIds + distinctOtherTaskIds == itemCount);

Assert.IsTrue(runningTasks.Count() > 0);
Assert.IsTrue(allOtherTasks.Count() > 0);
Expand Down

0 comments on commit 3a2084e

Please sign in to comment.