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
28 changes: 25 additions & 3 deletions tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Polly;
using Polly.Retry;

namespace Aspire.Hosting.Tests.Dcp;

Expand Down Expand Up @@ -1575,10 +1576,15 @@ public async Task PlainExecutable_ExtensionMode_SupportedDebugMode_RunsInIde()
// Act
await appExecutor.RunApplicationAsync();

await Task.Delay(2000);
// Assert
var dcpExes = kubernetesService.CreatedResources.OfType<Executable>().ToList();
Assert.Equal(2, dcpExes.Count);
List<Executable> dcpExes = [];
var haveExes = RetryTillTrueOrTimeout(() =>
{
dcpExes.Clear();
dcpExes.AddRange(kubernetesService.CreatedResources.OfType<Executable>());
return dcpExes.Count == 2;
}, TestConstants.DefaultOrchestratorTestTimeout);
Assert.True(haveExes, $"Expected two running but instead got {dcpExes.Count}");

var debuggableExe = Assert.Single(dcpExes, e => e.AppModelResourceName == "TestExecutable");
Assert.Equal(ExecutionType.IDE, debuggableExe.Spec.ExecutionType);
Expand Down Expand Up @@ -2045,6 +2051,22 @@ private static DcpExecutor CreateAppExecutor(
developerCertificateService);
}

private static bool RetryTillTrueOrTimeout(Func<bool> check, int timeoutMilliseconds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use AssertIsTrueRetryAsync from AsyncTestHelpers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I do not like it 😄 It does not allow me to set the maximum delay between attempts, it forces async behavior (which I do not need here), and it does not allow me to set the timeout, only maximum number of retries.

If it turns out that we use the new method in other DCP executor tests, I will think about moving it to some utility class.

{
var retry = new ResiliencePipelineBuilder<bool>()
.AddRetry(new RetryStrategyOptions<bool>
{
BackoffType = DelayBackoffType.Exponential,
Delay = TimeSpan.FromMilliseconds(200),
MaxDelay = TimeSpan.FromSeconds(2),
MaxRetryAttempts = int.MaxValue,
ShouldHandle = args => ValueTask.FromResult(!args.Outcome.Result)
})
.AddTimeout(TimeSpan.FromMilliseconds(timeoutMilliseconds))
.Build();
return retry.Execute(check);
}

private sealed class TestExecutableResource(string directory) : ExecutableResource("TestExecutable", "test", directory);
private sealed class TestOtherExecutableResource(string directory) : ExecutableResource("TestOtherExecutable", "test-other", directory);

Expand Down