From 0edd541a52cdc5db8d12502ecd670eccd4831dd3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 15:56:15 +0000 Subject: [PATCH] fix(tests): replace WaitForJobAsync with Task.Delay to avoid concurrent SQLite access in ProcessJob_HandlerFails_MarksJobAsFailed Agent-Logs-Url: https://github.com/JerrettDavis/StableDiffusionStudio/sessions/e0fa7a79-1443-46b7-a1b0-c32cc9390a9d Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> --- .../Jobs/BackgroundJobProcessorTests.cs | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/tests/StableDiffusionStudio.Infrastructure.Tests/Jobs/BackgroundJobProcessorTests.cs b/tests/StableDiffusionStudio.Infrastructure.Tests/Jobs/BackgroundJobProcessorTests.cs index 34baa6d..0f89bf6 100644 --- a/tests/StableDiffusionStudio.Infrastructure.Tests/Jobs/BackgroundJobProcessorTests.cs +++ b/tests/StableDiffusionStudio.Infrastructure.Tests/Jobs/BackgroundJobProcessorTests.cs @@ -98,13 +98,13 @@ public async Task ProcessJob_HandlerFails_MarksJobAsFailed() using var cts = new CancellationTokenSource(); await processor.StartAsync(cts.Token); await channel.Writer.WriteAsync(job.Id); - - var failed = await WaitForJobAsync(job.Id, j => j.Status == JobStatus.Failed, timeoutMs: 5000); - + await Task.Delay(500); cts.Cancel(); try { await processor.StopAsync(CancellationToken.None); } catch (OperationCanceledException) { } - failed.Status.Should().Be(JobStatus.Failed); + await using var verifyCtx = new AppDbContext(_dbOptions); + var failed = await verifyCtx.JobRecords.FindAsync(job.Id); + failed!.Status.Should().Be(JobStatus.Failed); failed.ErrorMessage.Should().Contain("Something broke"); } @@ -279,25 +279,6 @@ public async Task ProcessJob_MultipleJobs_AllComplete() } } - private async Task WaitForJobAsync(Guid jobId, Func predicate, int timeoutMs = 3000) - { - var sw = System.Diagnostics.Stopwatch.StartNew(); - while (sw.ElapsedMilliseconds < timeoutMs) - { - await using var verifyCtx = new AppDbContext(_dbOptions); - var job = await verifyCtx.JobRecords.FindAsync(jobId); - if (job is not null && predicate(job)) - return job; - - await Task.Delay(100); - } - - await using var finalCtx = new AppDbContext(_dbOptions); - var final = await finalCtx.JobRecords.FindAsync(jobId) - ?? throw new InvalidOperationException($"Job {jobId} not found while waiting for state transition."); - return final; - } - private class TestJobHandler : IJobHandler { private readonly Action _action;