File: ApplicationModel\TestingAnnotation.cs
Web Access
Project: src\src\Aspire.Hosting\Aspire.Hosting.csproj (Aspire.Hosting)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.Diagnostics.CodeAnalysis;
 
namespace Aspire.Hosting.ApplicationModel;
 
/// <summary>
/// Marks a resource whose completion contributes to the lifetime and outcome of an <c>aspire test</c> run.
/// </summary>
/// <remarks>
/// The annotation has no effect on normal application runs. Test resources must publish a terminal
/// resource state and an exit code; zero indicates success. Failure to start also indicates failure.
/// A collector configured through <c>WithTesting</c> publishes individual results alongside
/// resource execution. Both execution and collection contribute to the test run's completion.
/// </remarks>
[Experimental(TestingDiagnostics.DiagnosticId, UrlFormat = TestingDiagnostics.UrlFormat)]
public sealed class TestingAnnotation : IResourceAnnotation
{
    /// <summary>
    /// Creates an annotation marking a test resource for resource-based completion.
    /// </summary>
    public TestingAnnotation()
    {
    }
 
    /// <summary>
    /// Gets or sets the time allowed for the runtime result collector to complete.
    /// </summary>
    /// <value>
    /// A positive duration no greater than <c>4,294,967,294</c> milliseconds, or
    /// <see cref="System.Threading.Timeout.InfiniteTimeSpan"/> (the default) for no collector deadline.
    /// </value>
    /// <remarks>
    /// The deadline begins when collection is scheduled, including time spent waiting for resource
    /// completion inside the callback. It does not bound resource startup or execution.
    /// Expiry cancels the collector context and fails collection without stopping other participants.
    /// Test-run cancellation, including the overall CLI deadline, always applies.
    /// </remarks>
    /// <exception cref="ArgumentOutOfRangeException">The value is not infinite or a supported positive duration.</exception>
    public TimeSpan Timeout
    {
        get;
        set
        {
            if (value != System.Threading.Timeout.InfiniteTimeSpan &&
                (value <= TimeSpan.Zero || value > TimeSpan.FromMilliseconds(uint.MaxValue - 1)))
            {
                throw new ArgumentOutOfRangeException(nameof(value), value, "The collector timeout must be infinite or a positive duration no greater than 4,294,967,294 milliseconds.");
            }
            field = value;
        }
    } = System.Threading.Timeout.InfiniteTimeSpan;
 
    internal Func<ResourceTestingContext, Task>? Collector { get; init; }
    internal TestingContext? TestingContext { get; init; }
    internal string? OutputPath { get; init; }
}