Reformat / cleanup
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 46s
NuGet Publish / publish-to-gitea (push) Successful in 56s

This commit is contained in:
Joseph Doherty
2026-02-21 08:10:36 -05:00
parent 4c6aaa5a3f
commit a70d8befae
176 changed files with 50555 additions and 49587 deletions

View File

@@ -1,9 +1,4 @@
using ZB.MOM.WW.CBDD.Core;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using ZB.MOM.WW.CBDD.Core.Transactions;
using ZB.MOM.WW.CBDD.Shared;
using Xunit;
namespace ZB.MOM.WW.CBDD.Tests;
@@ -12,7 +7,7 @@ public class AsyncTests : IDisposable
private readonly string _dbPath;
/// <summary>
/// Initializes a new instance of the <see cref="AsyncTests"/> class.
/// Initializes a new instance of the <see cref="AsyncTests" /> class.
/// </summary>
public AsyncTests()
{
@@ -20,7 +15,7 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Dispose.
/// Executes Dispose.
/// </summary>
public void Dispose()
{
@@ -29,14 +24,14 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Async_Transaction_Commit_Should_Persist_Data.
/// Executes Async_Transaction_Commit_Should_Persist_Data.
/// </summary>
[Fact]
public async Task Async_Transaction_Commit_Should_Persist_Data()
{
var ct = TestContext.Current.CancellationToken;
using (var db = new Shared.TestDbContext(_dbPath))
using (var db = new TestDbContext(_dbPath))
{
using (var txn = await db.BeginTransactionAsync(ct))
{
@@ -47,7 +42,7 @@ public class AsyncTests : IDisposable
}
// Verify with new storage engine instance
using var db2 = new Shared.TestDbContext(_dbPath);
using var db2 = new TestDbContext(_dbPath);
var doc1 = db2.AsyncDocs.FindById(1);
doc1.ShouldNotBeNull();
doc1.Name.ShouldBe("Async1");
@@ -58,14 +53,14 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Async_Transaction_Rollback_Should_Discard_Data.
/// Executes Async_Transaction_Rollback_Should_Discard_Data.
/// </summary>
[Fact]
public async Task Async_Transaction_Rollback_Should_Discard_Data()
{
var ct = TestContext.Current.CancellationToken;
using var db = new Shared.TestDbContext(_dbPath);
using var db = new TestDbContext(_dbPath);
using (var txn = await db.BeginTransactionAsync(ct))
{
db.AsyncDocs.Insert(new AsyncDoc { Id = 3, Name = "RollbackMe" });
@@ -76,12 +71,12 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Bulk_Async_Insert_Should_Persist_Data.
/// Executes Bulk_Async_Insert_Should_Persist_Data.
/// </summary>
[Fact]
public async Task Bulk_Async_Insert_Should_Persist_Data()
{
using var db = new Shared.TestDbContext(_dbPath);
using var db = new TestDbContext(_dbPath);
var docs = Enumerable.Range(1, 100).Select(i => new AsyncDoc { Id = i + 5000, Name = $"Bulk{i}" });
var ids = await db.AsyncDocs.InsertBulkAsync(docs);
@@ -94,23 +89,20 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Bulk_Async_Update_Should_Persist_Changes.
/// Executes Bulk_Async_Update_Should_Persist_Changes.
/// </summary>
[Fact]
public async Task Bulk_Async_Update_Should_Persist_Changes()
{
using var db = new Shared.TestDbContext(_dbPath);
using var db = new TestDbContext(_dbPath);
// 1. Insert 100 docs
var docs = Enumerable.Range(1, 100).Select(i => new AsyncDoc { Id = i + 6000, Name = $"Original{i}" }).ToList();
await db.AsyncDocs.InsertBulkAsync(docs);
// 2. Update all docs
foreach (var doc in docs)
{
doc.Name = $"Updated{doc.Id - 6000}";
}
foreach (var doc in docs) doc.Name = $"Updated{doc.Id - 6000}";
var count = await db.AsyncDocs.UpdateBulkAsync(docs);
int count = await db.AsyncDocs.UpdateBulkAsync(docs);
count.ShouldBe(100);
@@ -121,23 +113,24 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes High_Concurrency_Async_Commits.
/// Executes High_Concurrency_Async_Commits.
/// </summary>
[Fact]
public async Task High_Concurrency_Async_Commits()
{
var ct = TestContext.Current.CancellationToken;
using var db = new Shared.TestDbContext(Path.Combine(Path.GetTempPath(), $"cbdd_async_concurrency_{Guid.NewGuid()}.db"));
int threadCount = 2;
int docsPerThread = 50;
using var db =
new TestDbContext(Path.Combine(Path.GetTempPath(), $"cbdd_async_concurrency_{Guid.NewGuid()}.db"));
var threadCount = 2;
var docsPerThread = 50;
var tasks = Enumerable.Range(0, threadCount).Select(async i =>
{
// Test mix of implicit and explicit transactions
for (int j = 0; j < docsPerThread; j++)
for (var j = 0; j < docsPerThread; j++)
{
int id = (i * docsPerThread) + j + 8000;
int id = i * docsPerThread + j + 8000;
await db.AsyncDocs.InsertAsync(new AsyncDoc { Id = id, Name = $"Thread{i}_Doc{j}" });
}
});
@@ -146,7 +139,7 @@ public class AsyncTests : IDisposable
await db.SaveChangesAsync(ct);
// Verify count
var count = db.AsyncDocs.Scan(_ => true).Count();
int count = db.AsyncDocs.Scan(_ => true).Count();
count.ShouldBe(threadCount * docsPerThread);
}
}
}