fix(host): resolve Host-012..015 — consume DownIfAlone in HOCON, sub-second timing precision, config-driven Serilog sinks, transient-only startup retry

This commit is contained in:
Joseph Doherty
2026-05-17 03:18:33 -04:00
parent eae4077414
commit aca65e85bb
9 changed files with 395 additions and 33 deletions

View File

@@ -57,9 +57,59 @@ public class StartupRetryTests
},
maxAttempts: 3,
initialDelay: TimeSpan.FromMilliseconds(1),
NullLogger.Instance));
NullLogger.Instance,
isTransient: _ => true));
Assert.Equal(3, attempts);
Assert.Equal("failure 3", ex.Message);
}
[Fact]
public async Task ExecuteWithRetry_NonTransientFailure_RethrowsAfterSingleAttempt()
{
// Host-015: a permanent failure (e.g. a schema-version mismatch) must NOT be
// retried — retrying it cannot succeed and only delays the fatal exit by
// minutes. The isTransient predicate classifies it as non-retryable, so the
// operation runs exactly once before the exception propagates.
var attempts = 0;
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
StartupRetry.ExecuteWithRetryAsync(
"test-op",
() =>
{
attempts++;
throw new InvalidOperationException("permanent schema mismatch");
},
maxAttempts: 8,
initialDelay: TimeSpan.FromMilliseconds(1),
NullLogger.Instance,
isTransient: _ => false));
Assert.Equal(1, attempts);
Assert.Equal("permanent schema mismatch", ex.Message);
}
[Fact]
public async Task ExecuteWithRetry_TransientThenPermanent_StopsAtPermanent()
{
// A transient fault is retried; a subsequent permanent fault is not.
var attempts = 0;
await Assert.ThrowsAsync<InvalidOperationException>(() =>
StartupRetry.ExecuteWithRetryAsync(
"test-op",
() =>
{
attempts++;
if (attempts == 1)
throw new TimeoutException("transient");
throw new InvalidOperationException("permanent");
},
maxAttempts: 8,
initialDelay: TimeSpan.FromMilliseconds(1),
NullLogger.Instance,
isTransient: e => e is TimeoutException));
// 1 transient (retried) + 1 permanent (not retried) = 2.
Assert.Equal(2, attempts);
}
}