fix(host): resolve Host-005..011 — async startup, HOCON escaping, port-conflict check, dead-config cleanup, migration retry, log-level wiring; Host-002 flagged
This commit is contained in:
65
tests/ScadaLink.Host.Tests/StartupRetryTests.cs
Normal file
65
tests/ScadaLink.Host.Tests/StartupRetryTests.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace ScadaLink.Host.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Host-010: startup preconditions (database migration) must tolerate a database
|
||||
/// that is briefly unavailable at boot — common when an app container and its DB
|
||||
/// container start together — via a bounded retry with backoff.
|
||||
/// </summary>
|
||||
public class StartupRetryTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task ExecuteWithRetry_SucceedsFirstTry_RunsOnce()
|
||||
{
|
||||
var attempts = 0;
|
||||
await StartupRetry.ExecuteWithRetryAsync(
|
||||
"test-op",
|
||||
() => { attempts++; return Task.CompletedTask; },
|
||||
maxAttempts: 5,
|
||||
initialDelay: TimeSpan.FromMilliseconds(1),
|
||||
NullLogger.Instance);
|
||||
|
||||
Assert.Equal(1, attempts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteWithRetry_TransientFailures_RetriesUntilSuccess()
|
||||
{
|
||||
var attempts = 0;
|
||||
await StartupRetry.ExecuteWithRetryAsync(
|
||||
"test-op",
|
||||
() =>
|
||||
{
|
||||
attempts++;
|
||||
if (attempts < 3)
|
||||
throw new InvalidOperationException("db not ready");
|
||||
return Task.CompletedTask;
|
||||
},
|
||||
maxAttempts: 5,
|
||||
initialDelay: TimeSpan.FromMilliseconds(1),
|
||||
NullLogger.Instance);
|
||||
|
||||
Assert.Equal(3, attempts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteWithRetry_ExhaustsAttempts_RethrowsLastException()
|
||||
{
|
||||
var attempts = 0;
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||
StartupRetry.ExecuteWithRetryAsync(
|
||||
"test-op",
|
||||
() =>
|
||||
{
|
||||
attempts++;
|
||||
throw new InvalidOperationException($"failure {attempts}");
|
||||
},
|
||||
maxAttempts: 3,
|
||||
initialDelay: TimeSpan.FromMilliseconds(1),
|
||||
NullLogger.Instance));
|
||||
|
||||
Assert.Equal(3, attempts);
|
||||
Assert.Equal("failure 3", ex.Message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user