Skip to content

PostgreSQL persistent lifetime not working when setting --environment in Integration test #9093

Open
@amolenk

Description

@amolenk

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I've written integration tests using DistributedApplicationTestingBuilder. To shorten the test run, I use Persistent lifetime for my PostgreSQL container. I also set the environment to 'Testing' so I can detect that it's a test run in my AppHost:

var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireTest_AppHost>([
    "--environment=Testing",
], cancellationToken);

When running the test, the PostgreSQL container is restarted each time.

If I remove the environment parameter, the PostgreSQL doesn't restart each time and works as expected:

var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireTest_AppHost>(cancellationToken);

I can also set other parameters without breaking the Persistent Lifetime functionality. It's only when settings the --environment parameter that the container restarts each time.

Expected Behavior

I expect the PostgreSQL container not to restart, independent of whether or not I'm setting the environment.

Steps To Reproduce

  • Create an Aspire Starter app (aspire-starter template)
  • Add a test project (aspire-xunit template)
  • Add the Aspire.Hosting.PostgreSQL package to the AppHost
  • Add the PostgreSQL container:
    var postgres = builder.AddPostgres("postgres")
        .WithLifetime(ContainerLifetime.Persistent);
  • Add the environment parameter:
    var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireTest_AppHost>([
            "--environment=Testing",
    ], cancellationToken);
  • Run the test a couple of times. Each time, the PostgreSQL container will restart (I monitor this in the Docker Desktop dashboard)
  • Remove the --environment parameter
  • Run the test a couple of times again. The PostgreSQL container will stay alive and not restart.

Exceptions (if any)

No response

.NET Version info

.NET version 9.0.100

Anything else?

.NET Aspire version 9.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions