diff --git a/tests/Trax.Effect.Tests.Broadcaster/UnitTests/TrainEventReceiverServiceTests.cs b/tests/Trax.Effect.Tests.Broadcaster/UnitTests/TrainEventReceiverServiceTests.cs index bf4d54c..fea4a60 100644 --- a/tests/Trax.Effect.Tests.Broadcaster/UnitTests/TrainEventReceiverServiceTests.cs +++ b/tests/Trax.Effect.Tests.Broadcaster/UnitTests/TrainEventReceiverServiceTests.cs @@ -265,12 +265,18 @@ public async Task ConnectionFailure_RetriesInsteadOfCrashing() }); var service = CreateService(); - using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); + using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20)); await service.StartAsync(cts.Token); - // The initial retry delay is 5s — wait long enough for at least one retry - await Task.Delay(TimeSpan.FromSeconds(7)); + // The initial retry delay is 5s, so a second StartAsync invocation + // should land within ~5-6s of the first. Poll for the actual second + // call instead of sleeping a fixed window: the test then reflects the + // service's real retry timing rather than racing GitHub Actions + // scheduling overhead. + var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(15); + while (DateTime.UtcNow < deadline && callCount <= 1) + await Task.Delay(100); // Should not have crashed the host — service retries callCount.Should().BeGreaterThan(1, "the service should retry after connection failure"); diff --git a/tests/Trax.Effect.Tests.Integration/UnitTests/Services/DataContextLoggingProviderTests.cs b/tests/Trax.Effect.Tests.Integration/UnitTests/Services/DataContextLoggingProviderTests.cs index 68bdf6e..91f9ba2 100644 --- a/tests/Trax.Effect.Tests.Integration/UnitTests/Services/DataContextLoggingProviderTests.cs +++ b/tests/Trax.Effect.Tests.Integration/UnitTests/Services/DataContextLoggingProviderTests.cs @@ -192,8 +192,23 @@ public async Task FlushLoop_BatchesLogsToDatabase() for (var i = 0; i < 5; i++) logger.Log(LogLevel.Information, default, i, null, (s, _) => $"msg {s}"); - // Wait for the 1-second flush timer to tick once. - await Task.Delay(1500); + // Poll for the flush loop to land at least one batch instead of waiting + // a fixed window past the 1-second timer tick. CI scheduling can stretch + // the timer's wakeup well past 1.5s; once any log is persisted we know + // the flush path is working and can stop waiting. + var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(15); + var landed = 0; + while (DateTime.UtcNow < deadline) + { + context.Reset(); + landed = await context + .Logs.AsNoTracking() + .Where(l => l.Category == "TestCategory") + .CountAsync(); + if (landed >= 1) + break; + await Task.Delay(50); + } provider.Dispose(); context.Reset();