Skip to content

Commit

Permalink
remove filter & fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Oct 21, 2024
1 parent 6f828ac commit 9d38a0c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public async Task StartBackgroundQueue(DateTime endTime)
// Process each batch
var fileHashesList = missingThumbnails.Select(p => p.FileHash).ToList();
var queryItems = await _query.GetObjectsByFileHashAsync(fileHashesList);
if ( queryItems.Count == 0 )
{
break;
}

await _bgTaskQueue.QueueBackgroundWorkItemAsync(async _ =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,73 +222,4 @@ public async Task WorkThumbnailGeneration_MatchItem()
Assert.AreEqual(1,result.Count);
Assert.AreEqual(null,result.FirstOrDefault()!.Large);
}

[TestMethod]
public async Task FilterWorkThumbnailGeneration_Timeout()
{
var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue();
var thumbnailQuery = new FakeIThumbnailQuery(new List<ThumbnailItem>
{
new ThumbnailItem("12",null,null,null,null)
});

var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService(
new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(),
new FakeIThumbnailService(),
thumbnailQuery,
bgTaskQueue,
new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery())
);

var result = (await databaseThumbnailGenerationService.FilterAndWorkThumbnailGeneration(
new DateTime(2000,01,01,01,01,01, kind: DateTimeKind.Local),
new List<ThumbnailItem>
{
new ThumbnailItem("23478928939438234",null,null,null,null)
}, new List<FileIndexItem>
{
new FileIndexItem()
{
FileHash = "23478928939438234",
Status = FileIndexItem.ExifStatus.Ok
}
})).ToList();

Assert.AreEqual(0,result.Count);
}

[TestMethod]
public async Task FilterWorkThumbnailGeneration_MatchItem()
{
var bgTaskQueue = new FakeThumbnailBackgroundTaskQueue();
var thumbnailQuery = new FakeIThumbnailQuery(new List<ThumbnailItem>
{
new ThumbnailItem("12",null,null,null,null)
});

var databaseThumbnailGenerationService = new DatabaseThumbnailGenerationService(
new FakeIQuery(), new FakeIWebLogger(), new FakeIWebSocketConnectionsService(),
new FakeIThumbnailService(),
thumbnailQuery,
bgTaskQueue,
new UpdateStatusGeneratedThumbnailService(new FakeIThumbnailQuery())
);

var result = (await databaseThumbnailGenerationService.FilterAndWorkThumbnailGeneration(
new DateTime(3000,01,01,01,01,01, kind: DateTimeKind.Local),
new List<ThumbnailItem>
{
new ThumbnailItem("2437998234",null,null,null,null)
}, new List<FileIndexItem>
{
new FileIndexItem()
{
FileHash = "2437998234",
Status = FileIndexItem.ExifStatus.Ok
}
})).ToList();

Assert.AreEqual(1,result.Count);
Assert.AreEqual(null,result.FirstOrDefault()!.Large);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -613,19 +613,19 @@ await _thumbnailQuery.AddThumbnailRangeAsync(new List<ThumbnailResultDataTransfe


[TestMethod]
public async Task UnprocessedGeneratedThumbnails_EmptyDb()
public async Task GetMissingThumbnailsBatchAsync_EmptyDb()
{
var serviceScope = CreateNewScope("UnprocessedGeneratedThumbnails1");
var context = serviceScope.CreateScope().ServiceProvider
.GetRequiredService<ApplicationDbContext>();

var query = new ThumbnailQuery(context, null!, new FakeIWebLogger());
var result = await query.UnprocessedGeneratedThumbnails();
var result = await query.GetMissingThumbnailsBatchAsync(0,100);
Assert.AreEqual(0, result.Count);
}

[TestMethod]
public async Task UnprocessedGeneratedThumbnails_OneResult()
public async Task GetMissingThumbnailsBatchAsync_OneResult()
{
var serviceScope = CreateNewScope("UnprocessedGeneratedThumbnails2");
var context = serviceScope.CreateScope().ServiceProvider
Expand All @@ -635,12 +635,12 @@ public async Task UnprocessedGeneratedThumbnails_OneResult()
await context.SaveChangesAsync();

var query = new ThumbnailQuery(context, null!, new FakeIWebLogger());
var result = await query.UnprocessedGeneratedThumbnails();
var result = await query.GetMissingThumbnailsBatchAsync(0,100);
Assert.AreEqual(1, result.Count);
}

[TestMethod]
public async Task UnprocessedGeneratedThumbnails_OneResultOfTwo()
public async Task GetMissingThumbnailsBatchAsync_OneResultOfTwo()
{
var serviceScope = CreateNewScope("UnprocessedGeneratedThumbnails3");
var context = serviceScope.CreateScope().ServiceProvider
Expand All @@ -652,7 +652,7 @@ public async Task UnprocessedGeneratedThumbnails_OneResultOfTwo()
await context.SaveChangesAsync();

var query = new ThumbnailQuery(context, null!, new FakeIWebLogger());
var result = await query.UnprocessedGeneratedThumbnails();
var result = await query.GetMissingThumbnailsBatchAsync(0,100);
Assert.AreEqual(1, result.Count);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task SyncThumbnailTableAsyncTest_InvalidData_WithRealDbContext()
Assert.AreEqual(5, content.Count);

// should not overwrite the existing data
var counter = dbContext.Thumbnails.Count();
var counter = await dbContext.Thumbnails.CountAsync();

Assert.AreEqual(1, counter);

Expand Down Expand Up @@ -130,7 +130,8 @@ public async Task SyncThumbnailTableAsyncTest_IgnoreXmpFile()
ImageFormat = ExtensionRolesHelper.ImageFormat.xmp
}})).Count);

Assert.AreEqual(0, ( await query.UnprocessedGeneratedThumbnails() ).Count);
var result = await query.GetMissingThumbnailsBatchAsync(0,100);
Assert.AreEqual(0, result.Count);
}

[TestMethod]
Expand All @@ -146,6 +147,7 @@ public async Task SyncThumbnailTableAsyncTest_KeepJpeg()
ImageFormat = ExtensionRolesHelper.ImageFormat.jpg
}})).Count);

Assert.AreEqual(0, ( await query.UnprocessedGeneratedThumbnails() ).Count);
var result = await query.GetMissingThumbnailsBatchAsync(0,100);
Assert.AreEqual(0, result.Count);
}
}

0 comments on commit 9d38a0c

Please sign in to comment.