diff --git a/starsky/starsky.feature.thumbnail/Interfaces/IDatabaseThumbnailGenerationService.cs b/starsky/starsky.feature.thumbnail/Interfaces/IDatabaseThumbnailGenerationService.cs index e002a08ad8..17fa1fd2ba 100644 --- a/starsky/starsky.feature.thumbnail/Interfaces/IDatabaseThumbnailGenerationService.cs +++ b/starsky/starsky.feature.thumbnail/Interfaces/IDatabaseThumbnailGenerationService.cs @@ -1,9 +1,8 @@ -using System; using System.Threading.Tasks; namespace starsky.feature.thumbnail.Interfaces; public interface IDatabaseThumbnailGenerationService { - Task StartBackgroundQueue(DateTime endTime); + Task StartBackgroundQueue(); } diff --git a/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs b/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs index 55a4b7c889..9916aba41f 100644 --- a/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs +++ b/starsky/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationService.cs @@ -43,7 +43,7 @@ public DatabaseThumbnailGenerationService(IQuery query, IWebLogger logger, _updateStatusGeneratedThumbnailService = updateStatusGeneratedThumbnailService; } - public async Task StartBackgroundQueue(DateTime endTime) + public async Task StartBackgroundQueue() { if ( _thumbnailQuery.IsRunningJob() ) { @@ -55,7 +55,7 @@ await _bgTaskQueue.QueueBackgroundWorkItemAsync( "DatabaseThumbnailGenerationService"); } - internal async Task WorkThumbnailGenerationLoop() + private async Task WorkThumbnailGenerationLoop() { _thumbnailQuery.SetRunningJob(true); diff --git a/starsky/starsky.feature.thumbnail/Services/PeriodicThumbnailScanHostedService.cs b/starsky/starsky.feature.thumbnail/Services/PeriodicThumbnailScanHostedService.cs index 70ecb240c9..92a408d706 100644 --- a/starsky/starsky.feature.thumbnail/Services/PeriodicThumbnailScanHostedService.cs +++ b/starsky/starsky.feature.thumbnail/Services/PeriodicThumbnailScanHostedService.cs @@ -103,7 +103,7 @@ await timer.WaitForNextTickAsync(cancellationToken) ) await using var asyncScope = _factory.CreateAsyncScope(); var service = asyncScope.ServiceProvider .GetRequiredService(); - await service.StartBackgroundQueue(DateTime.UtcNow.Add(Period)); + await service.StartBackgroundQueue(); _executionCount++; // Executed PeriodicThumbnailScanHostedService _logger.LogDebug( diff --git a/starsky/starskytest/FakeMocks/FakeIDatabaseThumbnailGenerationService.cs b/starsky/starskytest/FakeMocks/FakeIDatabaseThumbnailGenerationService.cs index 4fe130623c..f754f92be5 100644 --- a/starsky/starskytest/FakeMocks/FakeIDatabaseThumbnailGenerationService.cs +++ b/starsky/starskytest/FakeMocks/FakeIDatabaseThumbnailGenerationService.cs @@ -8,7 +8,7 @@ public class FakeIDatabaseThumbnailGenerationService : IDatabaseThumbnailGenerat { public int Count { get; set; } - public Task StartBackgroundQueue(DateTime endTime) + public Task StartBackgroundQueue() { Count++; return Task.CompletedTask; diff --git a/starsky/starskytest/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationServiceTest.cs b/starsky/starskytest/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationServiceTest.cs index 3ab3b9c301..f6da92684d 100644 --- a/starsky/starskytest/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationServiceTest.cs +++ b/starsky/starskytest/starsky.feature.thumbnail/Services/DatabaseThumbnailGenerationServiceTest.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -6,6 +5,7 @@ using starsky.feature.thumbnail.Services; using starsky.foundation.database.Models; using starsky.foundation.thumbnailgeneration.Services; +using starskytest.FakeCreateAn; using starskytest.FakeMocks; namespace starskytest.starsky.feature.thumbnail.Services; @@ -13,9 +13,8 @@ namespace starskytest.starsky.feature.thumbnail.Services; [TestClass] public class DatabaseThumbnailGenerationServiceTest { - [TestMethod] - public async Task StartBackgroundQueue_NoContentSoNotFired() + public async Task StartBackgroundQueue_NoContentSoHitOnce() { var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue(); var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService( @@ -26,21 +25,20 @@ public async Task StartBackgroundQueue_NoContentSoNotFired() new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery()) ); - await databaseThumbnailGenerationService.StartBackgroundQueue( - DateTime.UtcNow.Add(TimeSpan.FromMinutes(1))); - - Assert.AreEqual(0,bgTaskQueue.Count()); + await databaseThumbnailGenerationService.StartBackgroundQueue(); + + Assert.AreEqual(1, bgTaskQueue.Count()); } - + [TestMethod] public async Task StartBackgroundQueue_OneItemSoTrigger() { var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue(); var thumbnailQuery = new FakeIThumbnailQuery(new List { - new ThumbnailItem("12",null,null,null,null) + new("12", null, null, null, null) }); - + var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService( new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(), new FakeIThumbnailService(), @@ -48,23 +46,22 @@ public async Task StartBackgroundQueue_OneItemSoTrigger() bgTaskQueue, new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery()) ); - - await databaseThumbnailGenerationService.StartBackgroundQueue( - DateTime.UtcNow.Add(TimeSpan.FromMinutes(1))); - - Assert.AreEqual(1,bgTaskQueue.Count()); + + await databaseThumbnailGenerationService.StartBackgroundQueue(); + + Assert.AreEqual(1, bgTaskQueue.Count()); } - + [TestMethod] public async Task WorkThumbnailGeneration_ZeroItems() { var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue(); var thumbnailQuery = new FakeIThumbnailQuery(new List { - new ThumbnailItem("12",null,null,null,null) + new("12", null, null, null, null) }); - + var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService( new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(), new FakeIThumbnailService(), @@ -72,11 +69,11 @@ public async Task WorkThumbnailGeneration_ZeroItems() bgTaskQueue, new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery()) ); - + var result = await databaseThumbnailGenerationService.WorkThumbnailGeneration( new List(), new List()); - - Assert.AreEqual(0,result.Count()); + + Assert.AreEqual(0, result.Count()); } [TestMethod] @@ -85,9 +82,9 @@ public async Task WorkThumbnailGeneration_NotFoundItem_Database() var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue(); var thumbnailQuery = new FakeIThumbnailQuery(new List { - new ThumbnailItem("12",null,null,null,null) + new("12", null, null, null, null) }); - + var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService( new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(), new FakeIThumbnailService(), @@ -96,33 +93,31 @@ public async Task WorkThumbnailGeneration_NotFoundItem_Database() new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery( new List())) ); - - var result = (await databaseThumbnailGenerationService.WorkThumbnailGeneration( - new List - { - new ThumbnailItem("74283reiotfskl",null,null,null,null) - }, new List + + var result = ( await databaseThumbnailGenerationService.WorkThumbnailGeneration( + new List { new("74283rei_ot_fs_kl", null, null, null, null) }, + new List { - new FileIndexItem() + new() { - FileHash = "74283reiotfskl", + FileHash = "74283rei_ot_fs_kl", Status = FileIndexItem.ExifStatus.NotFoundSourceMissing } - })).ToList(); - - Assert.AreEqual(1,result.Count); + }) ).ToList(); + + Assert.AreEqual(1, result.Count); Assert.IsFalse(result.FirstOrDefault()!.Large); } - + [TestMethod] public async Task WorkThumbnailGeneration_NotFoundItem_2() { var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue(); var thumbnailQuery = new FakeIThumbnailQuery(new List { - new ThumbnailItem("74283reiotfskl",null,null,null,null) + new("74283rei_ot_fs_kl", null, null, null, null) }); - + var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService( new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(), new FakeIThumbnailService(new FakeSelectorStorage()), @@ -130,74 +125,69 @@ public async Task WorkThumbnailGeneration_NotFoundItem_2() bgTaskQueue, new UpdateStatusGeneratedThumbnailService(thumbnailQuery) ); - - var result = (await databaseThumbnailGenerationService.WorkThumbnailGeneration( - new List - { - new ThumbnailItem("74283reiotfskl",null,null,null,null) - }, new List + + var result = ( await databaseThumbnailGenerationService.WorkThumbnailGeneration( + new List { new("74283rei_ot_fs_kl", null, null, null, null) }, + new List { - new FileIndexItem() + new() { - FileHash = "74283reiotfskl", + FileHash = "74283rei_ot_fs_kl", FilePath = "/test.jpg", Status = FileIndexItem.ExifStatus.Ok } - })).ToList(); - - Assert.AreEqual(1,result.Count); - Assert.AreEqual(0,(await thumbnailQuery.Get( "74283reiotfskl")).Count); + }) ).ToList(); + + Assert.AreEqual(1, result.Count); + Assert.AreEqual(0, ( await thumbnailQuery.Get("74283rei_ot_fs_kl") ).Count); } - - + + [TestMethod] public async Task WorkThumbnailGeneration_FoundUpdate() { var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue(); var thumbnailQuery = new FakeIThumbnailQuery(new List { - new ThumbnailItem("345742938fsdjkdfkj",null,null,null,null) + new("345742938fs_jk_df_kj", null, null, null, null) }); - + var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService( new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(), - new FakeIThumbnailService(new FakeSelectorStorage(new FakeIStorage(new List(), new List - { - "/test.jpg" - }, new List{FakeCreateAn.CreateAnImage.Bytes.ToArray()}))), + new FakeIThumbnailService(new FakeSelectorStorage(new FakeIStorage(new List(), + new List { "/test.jpg" }, + new List { CreateAnImage.Bytes.ToArray() }))), thumbnailQuery, bgTaskQueue, new UpdateStatusGeneratedThumbnailService(thumbnailQuery) ); - - var result = (await databaseThumbnailGenerationService.WorkThumbnailGeneration( - new List - { - new ThumbnailItem("345742938fsdjkdfkj",null,null,null,null) - }, new List + + var result = ( await databaseThumbnailGenerationService.WorkThumbnailGeneration( + new List { new("345742938fs_jk_df_kj", null, null, null, null) }, + new List { - new FileIndexItem() + new() { - FileHash = "345742938fsdjkdfkj", + FileHash = "345742938fs_jk_df_kj", FilePath = "/test.jpg", Status = FileIndexItem.ExifStatus.Ok } - })).ToList(); - - Assert.AreEqual(1,result.Count); - Assert.AreEqual(1,(await thumbnailQuery.Get( "345742938fsdjkdfkj")).Count); - Assert.AreEqual(null,result.FirstOrDefault()!.Large); + }) ).ToList(); + + Assert.AreEqual(1, result.Count); + Assert.AreEqual(1, ( await thumbnailQuery.Get("345742938fs_jk_df_kj") ).Count); + Assert.AreEqual(null, result.FirstOrDefault()!.Large); } - + [TestMethod] public async Task WorkThumbnailGeneration_MatchItem() { var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue(); var thumbnailQuery = new FakeIThumbnailQuery(new List { - new ThumbnailItem("12",null,null,null,null) + new("12", null, null, null, null) }); - + var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService( new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(), new FakeIThumbnailService(), @@ -205,21 +195,15 @@ public async Task WorkThumbnailGeneration_MatchItem() bgTaskQueue, new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery()) ); - - var result = (await databaseThumbnailGenerationService.WorkThumbnailGeneration( - new List - { - new ThumbnailItem("74283reiotfskl",null,null,null,null) - }, new List + + var result = ( await databaseThumbnailGenerationService.WorkThumbnailGeneration( + new List { new("345742938fs_jk_df_kj", null, null, null, null) }, + new List { - new FileIndexItem() - { - FileHash = "74283reiotfskl", - Status = FileIndexItem.ExifStatus.Ok - } - })).ToList(); - - Assert.AreEqual(1,result.Count); - Assert.AreEqual(null,result.FirstOrDefault()!.Large); + new() { FileHash = "345742938fs_jk_df_kj", Status = FileIndexItem.ExifStatus.Ok } + }) ).ToList(); + + Assert.AreEqual(1, result.Count); + Assert.AreEqual(null, result.FirstOrDefault()!.Large); } }