Skip to content

Support DistributedApplicationTestingBuilder with IsPublishMode == true #9087

@eerhardt

Description

@eerhardt

Trying to write a test that uses DistributedApplicationTestingBuilder.CreateAsync to test my publisher. In order to test my publisher against a sample app, I have:

        using var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.Sample_AppHost>();
        builder.AddXunitLogging(Output);
        builder.Services.AddSingleton<IPublishingActivityProgressReporter>(_ => NullPublishingActivityProgressReporter.Instance);
        builder.Services.Configure<MyPublisherOptions>("mypub", options =>
        {
            options.OutputPath = _tempOutputDir.FullName;
        });

        await using var app = await builder.BuildAsync();

        await app.StartAsync();

        var model = app.Services.GetRequiredService<DistributedApplicationModel>();
        var publisher = app.Services.GetKeyedService<IDistributedApplicationPublisher>("mypub");

        Assert.NotNull(publisher);

        await publisher.PublishAsync(model, default);

The issue is if I do DistributedApplicationTestingBuilder.CreateAsync<Projects.Sample_AppHost>(), it creates the DistributedApplication with IsRunMode == true. But I need to execute the AppHost in Publish mode.

As far I as can tell, there isn't a clean way to set this up. I can pass in --publisher, but that requires a publisher to be passed. And so when DistributedApplicationTestingBuilder.CreateAsync runs, it will run the Main method of the sample app, which will kick off a publish operation. But my test is also publishing concurrently. This creates problems since they are both publishing.

cc @captainsafia @mitchdenny

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-testingIssues pertaining to the APIs in Aspire.Hosting.Testing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions