Files
CBDD/tests/CBDD.Tests/Indexing/GeospatialStressTests.cs
Joseph Doherty a70d8befae
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 46s
NuGet Publish / publish-to-gitea (push) Successful in 56s
Reformat / cleanup
2026-02-21 08:10:36 -05:00

57 lines
1.7 KiB
C#

using ZB.MOM.WW.CBDD.Shared;
namespace ZB.MOM.WW.CBDD.Tests;
public class GeospatialStressTests : IDisposable
{
private readonly TestDbContext _db;
private readonly string _dbPath;
/// <summary>
/// Initializes database state for geospatial stress tests.
/// </summary>
public GeospatialStressTests()
{
_dbPath = Path.Combine(Path.GetTempPath(), $"geo_stress_{Guid.NewGuid():N}.db");
_db = new TestDbContext(_dbPath);
}
/// <summary>
/// Disposes test resources and removes generated files.
/// </summary>
public void Dispose()
{
_db.Dispose();
if (File.Exists(_dbPath)) File.Delete(_dbPath);
string wal = Path.ChangeExtension(_dbPath, ".wal");
if (File.Exists(wal)) File.Delete(wal);
}
/// <summary>
/// Verifies spatial index handles node splits and query operations under load.
/// </summary>
[Fact]
public void SpatialIndex_Should_Handle_Node_Splits_And_Queries()
{
const int count = 350;
for (var i = 0; i < count; i++)
_db.GeoItems.Insert(new GeoEntity
{
Name = $"pt-{i}",
Location = (40.0 + i * 0.001, -73.0 - i * 0.001)
});
_db.SaveChanges();
var all = _db.GeoItems.Within("idx_spatial", (39.5, -74.5), (40.5, -72.5)).ToList();
all.Count.ShouldBe(count);
var subset = _db.GeoItems.Within("idx_spatial", (40.05, -73.30), (40.25, -73.05)).ToList();
subset.Count.ShouldBeGreaterThan(0);
subset.Count.ShouldBeLessThan(count);
var near = _db.GeoItems.Near("idx_spatial", (40.10, -73.10), 30.0).ToList();
near.Count.ShouldBeGreaterThan(0);
}
}