From 08b16e43ed3871728d4838daf987b02a6c625bcb Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Fri, 30 Apr 2021 12:54:47 -0400 Subject: [PATCH 1/2] Fix listing jobs not returning progress --- .../Controllers/JobController.cs | 13 +++++++++++-- src/Tgstation.Server.Host/Jobs/IJobManager.cs | 4 ++-- src/Tgstation.Server.Host/Jobs/JobManager.cs | 2 +- .../Instance/RepositoryTest.cs | 10 ++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/JobController.cs b/src/Tgstation.Server.Host/Controllers/JobController.cs index feb2ea4577..49613a329f 100644 --- a/src/Tgstation.Server.Host/Controllers/JobController.cs +++ b/src/Tgstation.Server.Host/Controllers/JobController.cs @@ -72,7 +72,7 @@ namespace Tgstation.Server.Host.Controllers .Include(x => x.CancelledBy) .Where(x => x.Instance.Id == Instance.Id && !x.StoppedAt.HasValue) .OrderByDescending(x => x.StartedAt))), - null, + AddJobProgressResponseTransformer, page, pageSize, cancellationToken); @@ -99,7 +99,7 @@ namespace Tgstation.Server.Host.Controllers .Include(x => x.CancelledBy) .Where(x => x.Instance.Id == Instance.Id) .OrderByDescending(x => x.StartedAt))), - null, + AddJobProgressResponseTransformer, page, pageSize, cancellationToken); @@ -168,5 +168,14 @@ namespace Tgstation.Server.Host.Controllers api.Progress = jobManager.JobProgress(job); return Json(api); } + + /// + /// Supplements s with their . + /// + /// The to augment. + private void AddJobProgressResponseTransformer(JobResponse jobResponse) + { + jobResponse.Progress = jobManager.JobProgress(jobResponse); + } } } diff --git a/src/Tgstation.Server.Host/Jobs/IJobManager.cs b/src/Tgstation.Server.Host/Jobs/IJobManager.cs index d0d53255a2..04e8079022 100644 --- a/src/Tgstation.Server.Host/Jobs/IJobManager.cs +++ b/src/Tgstation.Server.Host/Jobs/IJobManager.cs @@ -13,9 +13,9 @@ namespace Tgstation.Server.Host.Jobs /// /// Get the for a /// - /// The to get for + /// The to get for /// The of - int? JobProgress(Job job); + int? JobProgress(Api.Models.Internal.Job job); /// /// Registers a given and begins running it diff --git a/src/Tgstation.Server.Host/Jobs/JobManager.cs b/src/Tgstation.Server.Host/Jobs/JobManager.cs index b71e9bb140..52e068371e 100644 --- a/src/Tgstation.Server.Host/Jobs/JobManager.cs +++ b/src/Tgstation.Server.Host/Jobs/JobManager.cs @@ -303,7 +303,7 @@ namespace Tgstation.Server.Host.Jobs } /// - public int? JobProgress(Job job) + public int? JobProgress(Api.Models.Internal.Job job) { if (job == null) throw new ArgumentNullException(nameof(job)); diff --git a/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs b/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs index 2accf9c5ba..7ce4dac454 100644 --- a/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs @@ -69,6 +69,16 @@ namespace Tgstation.Server.Tests.Instance clone = await repositoryClient.Clone(cloneRequest, cancellationToken).ConfigureAwait(false); + // throwing this small jobs consistency test in here + await Task.Delay(TimeSpan.FromSeconds(20), cancellationToken).ConfigureAwait(false); + var activeJobs = await JobsClient.ListActive(null, cancellationToken); + var allJobs = await JobsClient.List(null, cancellationToken).ConfigureAwait(false); + + Assert.IsTrue(activeJobs.Any(x => x.Id == clone.ActiveJob.Id)); + Assert.IsTrue(allJobs.Any(x => x.Id == clone.ActiveJob.Id)); + Assert.IsTrue(activeJobs.First(x => x.Id == clone.ActiveJob.Id).Progress.HasValue); + Assert.IsTrue(allJobs.First(x => x.Id == clone.ActiveJob.Id).Progress.HasValue); + await WaitForJob(clone.ActiveJob, 9000, false, null, cancellationToken).ConfigureAwait(false); var readAfterClone = await repositoryClient.Read(cancellationToken); From 5f056192208c5d3d6f1717997befdac31418d37c Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Fri, 30 Apr 2021 21:07:18 -0400 Subject: [PATCH 2/2] Fix a small issue when running integration tests with legacy settings json --- tests/Tgstation.Server.Tests/TestingServer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Tgstation.Server.Tests/TestingServer.cs b/tests/Tgstation.Server.Tests/TestingServer.cs index de938a16e0..b63a259fe3 100644 --- a/tests/Tgstation.Server.Tests/TestingServer.cs +++ b/tests/Tgstation.Server.Tests/TestingServer.cs @@ -111,6 +111,7 @@ namespace Tgstation.Server.Tests // SPECIFICALLY DELETE THE DEV APPSETTINGS, WE DON'T WANT IT IN THE WAY File.Delete("appsettings.Development.yml"); + File.Delete("appsettings.Development.json"); if (!String.IsNullOrEmpty(gitHubAccessToken)) args.Add(String.Format(CultureInfo.InvariantCulture, "General:GitHubAccessToken={0}", gitHubAccessToken));