-
Notifications
You must be signed in to change notification settings - Fork 769
Open
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
If a container starts, but then immediately exits, it receives a FailedToStart state. An executable doing the same thing however transitions Starting --> Running --> Finished
Expected Behavior
I'd expect the two scenarios to behave the same - going from Starting --> Running --> Finished. This is how executables behave, but containers go Starting --> FailedToStart
Steps To Reproduce
[Fact]
public async Task ContainerExitsImmediatelyAfterStart()
{
using var cts = DefaultCancellationTokenSource();
await using var builder = DistributedApplicationTestingBuilder.Create();
var container = builder.AddContainer("container", "alpine")
.WithEntrypoint("sh")
.WithArgs("-c", "echo Hello World;exit 732");
AddFakeLogging(container);
await using var app = builder.Build();
await app.StartAsync(cts.Token);
//IMO, not sure this case should really go to `FailedToStart`. The container did start, it just exited immediately.
// So I'd expect it to go to `Running`, and then immediately to `Exited`.
await app.ResourceNotifications.WaitForResourceAsync(container.Resource.Name, KnownResourceStates.FailedToStart, cts.Token);
// See https://github.com/dotnet/aspire/issues/10218#issuecomment-3712542734
await Task.Delay(1_000);
var snapshot = app.Services.GetFakeLogCollector().GetSnapshot();
Assert.EndsWith("Hello World", snapshot[3].Message);
}
[Fact]
public async Task ExecutableExitsImmediately()
{
using var cts = DefaultCancellationTokenSource();
await using var builder = DistributedApplicationTestingBuilder.Create();
var container = builder.AddExecutable("cmd", "cmd", "")
.WithArgs("/c", "echo Hello World& exit 732");
AddFakeLogging(container);
await using var app = builder.Build();
await app.StartAsync(cts.Token);
await app.ResourceNotifications.WaitForResourceAsync(container.Resource.Name, KnownResourceStates.Finished, cts.Token);
var snapshot = app.Services.GetFakeLogCollector().GetSnapshot();
Assert.True(snapshot.Any());
Assert.EndsWith("Hello World", snapshot[1].Message);
}Exceptions (if any)
No response
.NET Version info
No response
Anything else?
This seems to be a re-occurrence of #7491