Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Aspire.Hosting/DistributedApplicationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ await activityReporter.UpdateActivityStatusAsync(

if (!backchannelService.IsBackchannelExpected)
{
lifetime.StopApplication();
throw new DistributedApplicationException($"Publishing failed exception message: {ex.Message}", ex);
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Aspire.Hosting.Tests/DistributedApplicationRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.Publishing;
using Aspire.Hosting.Utils;
using Xunit;

namespace Aspire.Hosting.Tests;

public class DistributedApplicationRunnerTests(ITestOutputHelper outputHelper)
{
[Fact]
public void EnsureFailingPublishResultsInRunMethodThrowing()
{
var args = new[] { "--publisher", "explodingpublisher" };
using var builder = TestDistributedApplicationBuilder.Create(outputHelper, args);
#pragma warning disable ASPIREPUBLISHERS001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
builder.AddPublisher<ExplodingPublisher, ExplodingPublisherOptions>("explodingpublisher");
#pragma warning restore ASPIREPUBLISHERS001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
using var app = builder.Build();

var ex = Assert.Throws<AggregateException>(app.Run);

Assert.Collection(
ex.InnerExceptions,
e => Assert.Equal("Publishing failed exception message: Boom!", e.Message)
);
}
}

internal sealed class ExplodingPublisher : IDistributedApplicationPublisher
{
public Task PublishAsync(DistributedApplicationModel model, CancellationToken cancellationToken)
{
throw new NotImplementedException("Boom!");
}
}

internal sealed class ExplodingPublisherOptions
{
}