Fix a bunch of tests with auto-healing

This commit is contained in:
Timothy Baldridge 2020-04-09 21:54:02 -06:00
parent 0ed4f123af
commit a481f546c1
6 changed files with 82 additions and 7 deletions

View File

@ -28,6 +28,7 @@ namespace Wabbajack.BuildServer.Test
public AbsolutePath ServerPublicFolder => "public".RelativeTo(AbsolutePath.EntryPoint);
public AbsolutePath ServerArchivesFolder => "archives".RelativeTo(AbsolutePath.EntryPoint);
public AbsolutePath ServerUpdatesFolder => "updates".RelativeTo(AbsolutePath.EntryPoint);
public BuildServerFixture()

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Wabbajack.BuildServer.Model.Models;
using Wabbajack.BuildServer.Models.JobQueue;
using Wabbajack.BuildServer.Models.Jobs;
@ -22,7 +23,7 @@ namespace Wabbajack.BuildServer.Test
}
[Fact, Priority(0)]
public async Task CanIndexFiles()
public async Task CanIndexAndUpdateFiles()
{
var sql = Fixture.GetService<SqlService>();
var modId = long.MaxValue >> 1;
@ -76,6 +77,53 @@ namespace Wabbajack.BuildServer.Test
Assert.Equal($"Oldfile_{oldDataHash.ToHex()}_".RelativeTo(Fixture.ServerArchivesFolder), settings.PathForArchive(oldDataHash));
Assert.Equal($"Newfile_{newDataHash.ToHex()}_".RelativeTo(Fixture.ServerArchivesFolder), settings.PathForArchive(newDataHash));
Utils.Log($"Download Updating {oldDataHash} -> {newDataHash}");
await using var conn = await sql.Open();
await conn.ExecuteAsync("DELETE FROM dbo.DownloadStates WHERE Hash in (@OldHash, @NewHash);",
new {OldHash = (long)oldDataHash, NewHash = (long)newDataHash});
await sql.AddDownloadState(oldDataHash, new NexusDownloader.State
{
Game = Game.Oblivion,
ModID = modId,
FileID = oldFileId
});
await sql.AddDownloadState(newDataHash, new NexusDownloader.State
{
Game = Game.Oblivion,
ModID = modId,
FileID = newFileId
});
Assert.NotNull(await sql.GetNexusStateByHash(oldDataHash));
Assert.NotNull(await sql.GetNexusStateByHash(newDataHash));
// No nexus info, so no upgrade
var noUpgrade = await ClientAPI.GetModUpgrade(oldDataHash);
Assert.Null(noUpgrade);
// Add Nexus info
await sql.AddNexusModFiles(Game.Oblivion, modId, DateTime.Now,
new NexusApiClient.GetModFilesResponse
{
files = new List<NexusFileInfo>
{
new NexusFileInfo {category_name = "MAIN", file_id = newFileId, file_name = "New File"},
new NexusFileInfo {category_name = null, file_id = oldFileId, file_name = "Old File"}
}
});
var enqueuedUpgrade = await ClientAPI.GetModUpgrade(oldDataHash);
// Not Null because upgrade was enqueued
Assert.NotNull(enqueuedUpgrade);
await RunAllJobs();
Assert.True($"{oldDataHash.ToHex()}_{newDataHash.ToHex()}".RelativeTo(Fixture.ServerUpdatesFolder).IsFile);
}

View File

@ -99,14 +99,24 @@ namespace Wabbajack.BuildServer.Controllers
.OrderByDescending(s => s.LastValidationTime).FirstOrDefaultAsync();*/
if (state == null)
{
Utils.Log($"No original state for {startingHash}");
return NotFound("Original state not found");
}
var nexusState = state.State as NexusDownloader.State;
var nexusGame = nexusState.Game;
var mod_files = (await SQL.GetModFiles(nexusGame, nexusState.ModID)).files;
var nexusModFiles = await SQL.GetModFiles(nexusGame, nexusState.ModID);
if (nexusModFiles == null)
{
Utils.Log($"No nexus mod files for {startingHash}");
return NotFound("No nexus info");
}
var mod_files = nexusModFiles.files;
if (mod_files.Any(f => f.category_name != null && f.file_id == nexusState.FileID))
{
Utils.Log($"No available upgrade required for {nexusState.PrimaryKey}");
await Metric("not_required_upgrade", startingHash.ToString());
return BadRequest("Upgrade Not Required");
}
@ -115,6 +125,7 @@ namespace Wabbajack.BuildServer.Controllers
var newArchive = await FindAlternatives(nexusState, startingHash);
if (newArchive == null)
{
Utils.Log($"No available upgrade for {nexusState.PrimaryKey}");
return NotFound("No alternative available");
}

View File

@ -6,9 +6,11 @@ using Wabbajack.BuildServer.Model.Models;
using Wabbajack.BuildServer.Models.JobQueue;
using Wabbajack.BuildServer.Models.Jobs;
using Wabbajack.Common;
using Wabbajack.Common.Serialization.Json;
namespace Wabbajack.BuildServer.Models
{
[JsonName("PatchArchive")]
public class PatchArchive : AJobPayload
{
public override string Description => "Create a archive update patch";
@ -25,6 +27,7 @@ namespace Wabbajack.BuildServer.Models
Utils.Log($"Creating Patch ({Src} -> {DestPK})");
var cdnPath = CdnPath(Src, destHash);
cdnPath.Parent.CreateDirectory();
if (cdnPath.Exists)
return JobResult.Success();
@ -42,6 +45,12 @@ namespace Wabbajack.BuildServer.Models
Utils.Log($"Uploading Patch ({Src} -> {DestPK})");
int retries = 0;
if (settings.BunnyCDN_User == "TEST" && settings.BunnyCDN_Password == "TEST")
{
return JobResult.Success();
}
TOP:
using (var client = new FtpClient("storage.bunnycdn.com"))
{

View File

@ -517,9 +517,8 @@ namespace Wabbajack.BuildServer.Model.Models
{
await using var conn = await Open();
var result = await conn.QueryFirstOrDefaultAsync<string>(@"SELECT JsonState FROM dbo.DownloadStates
WHERE Hash = @hash AND PrimaryKey like 'NexusDownloader+State|%'
ORDER BY LastValidated DESC",
new {Hash = startingHash});
WHERE Hash = @hash AND PrimaryKey like 'NexusDownloader+State|%'",
new {Hash = (long)startingHash});
return result == null ? null : new Archive
{
State = result.FromJsonString<AbstractDownloadState>(),

View File

@ -17,8 +17,15 @@ namespace Wabbajack.Lib
public static async Task<Archive> GetModUpgrade(Hash hash)
{
using var response = await GetClient()
.GetAsync($"https://{Consts.WabbajackCacheHostname}/alternative/{hash.ToHex()}");
return !response.IsSuccessStatusCode ? null : (await response.Content.ReadAsStringAsync()).FromJsonString<Archive>();
.GetAsync($"{Consts.WabbajackBuildServerUri}alternative/{hash.ToHex()}");
if (response.IsSuccessStatusCode)
{
return (await response.Content.ReadAsStringAsync()).FromJsonString<Archive>();
}
Utils.Log($"No Upgrade for {hash}");
Utils.Log(await response.Content.ReadAsStringAsync());
return null;
}
/// <summary>