Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions tests/Aspire.Hosting.Azure.Tests/AzureSandboxesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
using Azure.Core;
using Azure.Provisioning.Resources;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Testing;

namespace Aspire.Hosting.Azure.Tests;

Expand Down Expand Up @@ -1586,13 +1588,28 @@ public async Task AzureDevComputeClientMarksRejectedCreateResponsesAsDefinite()
[Fact]
public async Task AzureDevComputeClientKeepsCancellationAfterRejectedCreateDefinite()
{
var handler = new RecordingHandler(_ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.Forbidden)));
var requestCount = 0;
var handler = new RecordingHandler(_ =>
{
Interlocked.Increment(ref requestCount);
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.Forbidden));
});
// Cancel when the client logs the 403 retry warning, after the rejection has been received and
// before the retry delay starts. A wall-clock timeout could fire while the request is still in flight.
using var cancellationTokenSource = new CancellationTokenSource();
var sink = new TestSink();
sink.MessageLogged += context =>
{
if (context.LogLevel == LogLevel.Warning)
{
cancellationTokenSource.Cancel();
}
};
var client = new AzureDevComputeClient(
new HttpClient(handler),
new RecordingTokenCredential(),
NullLogger.Instance,
new TestLogger(nameof(AzureDevComputeClient), sink, enabled: true),
TimeSpan.FromMinutes(1));
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(10));

var exception = await Assert.ThrowsAsync<AzureDevComputeCreateException>(() => client.CreateDiskImageAsync(
new AzureDevComputeResourceScope("sub", "rg", "sg", "westus3"),
Expand All @@ -1603,6 +1620,7 @@ public async Task AzureDevComputeClientKeepsCancellationAfterRejectedCreateDefin
},
cancellationTokenSource.Token));

Assert.Equal(1, requestCount);
Assert.False(exception.ResponseMayHaveBeenLost);
Assert.IsType<TaskCanceledException>(exception.OriginalException);
}
Expand Down
Loading