2020-08-05 00:34:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wabbajack.BuildServer.Test;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
|
|
|
|
using Wabbajack.Server.DataLayer;
|
|
|
|
|
using Wabbajack.Server.DTOs;
|
|
|
|
|
using Wabbajack.Server.Services;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Server.Test
|
|
|
|
|
{
|
|
|
|
|
public class MirroredFilesTests : ABuildServerSystemTest
|
|
|
|
|
{
|
|
|
|
|
public MirroredFilesTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanUploadAndDownloadMirroredFiles()
|
|
|
|
|
{
|
|
|
|
|
var file = new TempFile();
|
|
|
|
|
await file.Path.WriteAllBytesAsync(RandomData(1024 * 1024 * 6));
|
|
|
|
|
var dataHash = await file.Path.FileHashAsync();
|
2021-01-09 18:53:44 +00:00
|
|
|
|
Assert.NotNull(dataHash);
|
2020-08-05 00:34:09 +00:00
|
|
|
|
|
|
|
|
|
await Fixture.GetService<ArchiveMaintainer>().Ingest(file.Path);
|
2021-01-09 18:53:44 +00:00
|
|
|
|
Assert.True(Fixture.GetService<ArchiveMaintainer>().HaveArchive(dataHash!.Value));
|
2020-08-05 00:34:09 +00:00
|
|
|
|
|
|
|
|
|
var sql = Fixture.GetService<SqlService>();
|
|
|
|
|
|
|
|
|
|
await sql.UpsertMirroredFile(new MirroredFile
|
|
|
|
|
{
|
|
|
|
|
Created = DateTime.UtcNow,
|
|
|
|
|
Rationale = "Test File",
|
2021-01-09 18:53:44 +00:00
|
|
|
|
Hash = dataHash!.Value
|
2020-08-05 00:34:09 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var uploader = Fixture.GetService<MirrorUploader>();
|
2021-03-11 02:28:28 +00:00
|
|
|
|
uploader.ActiveFileSyncEnabled = false;
|
2020-08-05 00:34:09 +00:00
|
|
|
|
Assert.Equal(1, await uploader.Execute());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var archive = new Archive(new HTTPDownloader.State(MakeURL(dataHash.ToString())))
|
|
|
|
|
{
|
2021-01-09 18:53:44 +00:00
|
|
|
|
Hash = dataHash!.Value,
|
2020-08-05 00:34:09 +00:00
|
|
|
|
Size = file.Path.Size
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-06 03:54:04 +00:00
|
|
|
|
await using var file2 = new TempFile();
|
2020-08-05 00:34:09 +00:00
|
|
|
|
await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, file2.Path);
|
2021-03-06 03:54:04 +00:00
|
|
|
|
Assert.Equal(dataHash!.Value, await file2.Path.FileHashAsync());
|
2021-03-11 02:28:28 +00:00
|
|
|
|
|
|
|
|
|
var onServer = await uploader.GetHashesOnCDN();
|
|
|
|
|
Assert.Contains(dataHash.Value, onServer);
|
|
|
|
|
|
|
|
|
|
await uploader.DeleteOldMirrorFiles();
|
|
|
|
|
|
|
|
|
|
// Still in SQL so it will still exist
|
|
|
|
|
await using var file3 = new TempFile();
|
|
|
|
|
await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, file3.Path);
|
|
|
|
|
Assert.Equal(dataHash!.Value, await file3.Path.FileHashAsync());
|
|
|
|
|
|
|
|
|
|
// Enabling the sync should kill off the unattached file
|
|
|
|
|
uploader.ActiveFileSyncEnabled = true;
|
|
|
|
|
Assert.Equal(0, await uploader.Execute());
|
|
|
|
|
|
|
|
|
|
var onServer2 = await uploader.GetHashesOnCDN();
|
|
|
|
|
Assert.DoesNotContain(dataHash.Value, onServer2);
|
2020-08-05 00:34:09 +00:00
|
|
|
|
}
|
2020-11-02 00:30:49 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanQueueFiles()
|
|
|
|
|
{
|
|
|
|
|
var service = Fixture.GetService<MirrorQueueService>();
|
|
|
|
|
Assert.Equal(1, await service.Execute());
|
|
|
|
|
}
|
2020-08-05 00:34:09 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|