mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Merge pull request #267 from BinaryAlley/bugfix/fix-flaky-file-hash-service-callback-count
Fixes flaky FileHashService, LibraryPathTemplate and TranscodingCacheCoordinator tests
This commit is contained in:
3 files changed
+9
-4
No files matched your search
+4
-2
@@ -449,11 +449,13 @@ public class TranscodingCacheCoordinatorTests : IDisposable
|
|||||||
string cacheId = CreateCacheId();
|
string cacheId = CreateCacheId();
|
||||||
string cachePath = Path.Combine(_cacheRoot, cacheId);
|
string cachePath = Path.Combine(_cacheRoot, cacheId);
|
||||||
PublishEntry(cacheId, 50, 100);
|
PublishEntry(cacheId, 50, 100);
|
||||||
Thread.Sleep(200);
|
// The entry must be older than the grace period before the touch, and the touch must still be inside it when the reservation
|
||||||
|
// runs. A grace period of seconds keeps the second condition true on slow CI runners, where a few hundred milliseconds can pass between the two calls.
|
||||||
|
Thread.Sleep(2100);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
_sut.Touch(cacheId, TimeSpan.Zero);
|
_sut.Touch(cacheId, TimeSpan.Zero);
|
||||||
bool result = _sut.TryReserve(80, 100, TimeSpan.FromMilliseconds(100), out _);
|
bool result = _sut.TryReserve(80, 100, TimeSpan.FromSeconds(2), out _);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(result);
|
Assert.False(result);
|
||||||
|
|||||||
+2
-1
@@ -43,7 +43,8 @@ public class FileHashServiceTests
|
|||||||
shouldParallelizeReads: true,
|
shouldParallelizeReads: true,
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
callbackInvocationCount++;
|
// The callback is invoked concurrently by the parallel reads, so a plain increment could lose a count.
|
||||||
|
Interlocked.Increment(ref callbackInvocationCount);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
},
|
},
|
||||||
CancellationToken.None);
|
CancellationToken.None);
|
||||||
|
|||||||
+3
-1
@@ -14,6 +14,7 @@ namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedC
|
|||||||
public class LibraryPathTemplateTests
|
public class LibraryPathTemplateTests
|
||||||
{
|
{
|
||||||
private readonly LibraryPathTemplateFixture _libraryPathTemplateFixture = new();
|
private readonly LibraryPathTemplateFixture _libraryPathTemplateFixture = new();
|
||||||
|
private readonly LibraryPathPartFixture _libraryPathPartFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Create_WhenCalledWithParts_ShouldCreateTemplateWithThoseParts()
|
public void Create_WhenCalledWithParts_ShouldCreateTemplateWithThoseParts()
|
||||||
@@ -75,7 +76,8 @@ public class LibraryPathTemplateTests
|
|||||||
LibraryPathTemplate firstTemplate = _libraryPathTemplateFixture.Create();
|
LibraryPathTemplate firstTemplate = _libraryPathTemplateFixture.Create();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
LibraryPathTemplate secondTemplate = _libraryPathTemplateFixture.Create();
|
// The second template extends the first one, because two random templates can be identical (a single typed part of the same kind).
|
||||||
|
LibraryPathTemplate secondTemplate = LibraryPathTemplate.Create([.. firstTemplate.Parts, _libraryPathPartFixture.Create()]);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotEqual(firstTemplate, secondTemplate);
|
Assert.NotEqual(firstTemplate, secondTemplate);
|
||||||
|
|||||||
Reference in new issue
Block a user