This PR has a large blast radius because it takes the final step and bumps up the Controller to be fully async. We have historically done a piece-by-piece update, so all operations were already async but the controller interface was kept synchronous. With this update, the controller is now fully async and all tests are updated. Most places where the new C# compiler warns about function names not ending in `Async` were also adressed, giving a massive refactor change. Functionally, no changes are done.
52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Assert = NUnit.Framework.Legacy.ClassicAssert;
|
|
|
|
namespace Duplicati.UnitTest
|
|
{
|
|
public class Issue6425 : BasicSetupHelper
|
|
{
|
|
[Test]
|
|
[Category("Purge")]
|
|
public async Task TestPurgeFileSizeCalculationWithSharedBlocksAsync()
|
|
{
|
|
var blocksize = 1024 * 10; // 10KB blocks
|
|
|
|
var testopts = TestOptions;
|
|
testopts["blocksize"] = blocksize + "b";
|
|
testopts["no-backend-verification"] = "true";
|
|
|
|
var sharedContent = new byte[blocksize * 2];
|
|
new Random(42).NextBytes(sharedContent);
|
|
|
|
var file1 = Path.Combine(DATAFOLDER, "file1.dat");
|
|
var file2 = Path.Combine(DATAFOLDER, "file2.dat");
|
|
|
|
File.WriteAllBytes(file1, sharedContent);
|
|
File.WriteAllBytes(file2, sharedContent);
|
|
|
|
using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null))
|
|
{
|
|
var res = await c.BackupAsync(new[] { DATAFOLDER });
|
|
Assert.AreEqual(0, res.Errors.Count());
|
|
}
|
|
|
|
using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null))
|
|
{
|
|
var purgeResult = await c.PurgeFilesAsync(new Duplicati.Library.Utility.FilterExpression(new[] { file1 }));
|
|
|
|
Assert.AreEqual(0, purgeResult.Errors.Count());
|
|
|
|
Console.WriteLine($"Reported RemovedFileSize: {purgeResult.RemovedFileSize}");
|
|
Console.WriteLine($"File size: {sharedContent.Length}");
|
|
|
|
Assert.Less(purgeResult.RemovedFileSize, sharedContent.Length,
|
|
"RemovedFileSize should not count blocks still referenced by other files");
|
|
}
|
|
}
|
|
}
|
|
}
|