fix(notify,esg): classify dropped SMTP connections, OAuth2 token-endpoint outages and body-read connection loss as transient (NTF-2, ESG-1, WP4 task 4.6)
This commit is contained in:
@@ -102,14 +102,64 @@ public class SmtpErrorClassifierTests
|
||||
SmtpErrorClassifier.Classify(new OperationCanceledException(), cts.Token));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that an operation cancellation without a requested cancellation is classified as unknown.</summary>
|
||||
/// <summary>
|
||||
/// NTF-2: a cancellation the caller did not request is a timeout (HttpClient.Timeout on the
|
||||
/// OAuth2 token fetch surfaces as TaskCanceledException) and is transient. Before NTF-2 it
|
||||
/// was Unknown, which the outbox adapter parks as permanent.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Classify_OperationCanceledWithoutRequestedCancellation_IsUnknown()
|
||||
public void Classify_OperationCanceledWithoutRequestedCancellation_IsTransient()
|
||||
{
|
||||
// Not a recognised SMTP error, and cancellation was not requested.
|
||||
Assert.Equal(
|
||||
SmtpErrorClass.Unknown,
|
||||
SmtpErrorClass.Transient,
|
||||
SmtpErrorClassifier.Classify(new OperationCanceledException(), CancellationToken.None));
|
||||
Assert.Equal(
|
||||
SmtpErrorClass.Transient,
|
||||
SmtpErrorClassifier.Classify(new TaskCanceledException("HttpClient.Timeout"), CancellationToken.None));
|
||||
}
|
||||
|
||||
/// <summary>NTF-2: a dropped connection (MailKit's documented IOException) is transient, wrapped or not.</summary>
|
||||
[Fact]
|
||||
public void Classify_IOException_IsTransient_IncludingAWrappedSocketException()
|
||||
{
|
||||
Assert.Equal(SmtpErrorClass.Transient,
|
||||
SmtpErrorClassifier.Classify(new IOException("connection reset"), CancellationToken.None));
|
||||
Assert.Equal(SmtpErrorClass.Transient,
|
||||
SmtpErrorClassifier.Classify(
|
||||
new IOException("Unable to read data", new SocketException((int)SocketError.ConnectionReset)),
|
||||
CancellationToken.None));
|
||||
// An unrecognised wrapper whose cause is a socket failure is unwrapped too.
|
||||
Assert.Equal(SmtpErrorClass.Transient,
|
||||
SmtpErrorClassifier.Classify(
|
||||
new InvalidOperationException("wrapper", new TimeoutException()), CancellationToken.None));
|
||||
}
|
||||
|
||||
/// <summary>NTF-2: a TLS handshake that failed mid-way (relay restarting) is transient.</summary>
|
||||
[Fact]
|
||||
public void Classify_SslHandshakeException_IsTransient()
|
||||
{
|
||||
Assert.Equal(SmtpErrorClass.Transient,
|
||||
SmtpErrorClassifier.Classify(new MailKit.Security.SslHandshakeException("handshake failed"), CancellationToken.None));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NTF-2: OAuth2 token-endpoint failures are classified by HTTP status — no status (network),
|
||||
/// 5xx, 408 and 429 are transient; any other 4xx (a broken credential) is permanent.
|
||||
/// </summary>
|
||||
/// <param name="status">The token endpoint's status, or null for a network failure.</param>
|
||||
/// <param name="expected">The expected classification.</param>
|
||||
[Theory]
|
||||
[InlineData(null, SmtpErrorClass.Transient)]
|
||||
[InlineData(503, SmtpErrorClass.Transient)]
|
||||
[InlineData(500, SmtpErrorClass.Transient)]
|
||||
[InlineData(408, SmtpErrorClass.Transient)]
|
||||
[InlineData(429, SmtpErrorClass.Transient)]
|
||||
[InlineData(400, SmtpErrorClass.Permanent)]
|
||||
[InlineData(401, SmtpErrorClass.Permanent)]
|
||||
public void Classify_TokenEndpointHttpRequestException_ByStatus(int? status, SmtpErrorClass expected)
|
||||
{
|
||||
var ex = new HttpRequestException("token endpoint", null, (System.Net.HttpStatusCode?)status);
|
||||
Assert.Equal(expected, SmtpErrorClassifier.Classify(ex, CancellationToken.None));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that an unrecognised exception is classified as unknown.</summary>
|
||||
|
||||
Reference in New Issue
Block a user