Files
speckle-sharp-sdk/tests/Speckle.Sdk.Serialization.Tests/Framework/ExceptionSendCacheManager.cs
T
Adam Hathcock 377829adae
.NET Build and Publish / build (push) Has been cancelled
fix(main) exception test correction and token usage (#283)
* add parallelism on exception after count test

* use scoped token source correctly

* format

* Centralized token usage and made sqlite busy timeout be 5 seconds

* restore write parallelism to 4

* add to comment
2025-04-24 10:40:46 +00:00

48 lines
1.2 KiB
C#

using Speckle.Sdk.SQLite;
namespace Speckle.Sdk.Serialization.Tests.Framework;
public class ExceptionSendCacheManager(bool? hasObject = null, int? exceptionsAfter = null) : ISqLiteJsonCacheManager
{
private readonly object _lock = new();
private int _count;
public void Dispose() { }
public IReadOnlyCollection<(string Id, string Json)> GetAllObjects() => throw new NotImplementedException();
public void DeleteObject(string id) => CheckExceptions();
public string? GetObject(string id) => null;
public void SaveObject(string id, string json) => CheckExceptions();
public void UpdateObject(string id, string json) => CheckExceptions();
public void SaveObjects(IEnumerable<(string id, string json)> items) => CheckExceptions();
public bool HasObject(string objectId) => hasObject ?? throw new NotImplementedException();
private void CheckExceptions()
{
lock (_lock)
{
if (exceptionsAfter is not null)
{
if (exceptionsAfter.Value > _count)
{
_count++;
}
else
{
throw new Exception("Count exceeded");
}
}
else
{
throw new NotImplementedException();
}
}
}
}