testcontainers-dotnet-legacy icon indicating copy to clipboard operation
testcontainers-dotnet-legacy copied to clipboard

Method not found: Polly.Policy.TimeoutAsync(System.TimeSpan)

Open dogac00 opened this issue 4 years ago • 1 comments

Describe the bug I am trying to start a PostgreSqlContainer. Here is my PostgreSqlFixture class.

public class PostgreSqlFixture
    {
        private const string PostgreSqlImageName = "postgres:11.1";
        private readonly PostgreSqlContainer _container;
        public string ConnectionString => _container.ConnectionString;

        public PostgreSqlFixture() => 
            _container = new DatabaseContainerBuilder<PostgreSqlContainer>()
                .Begin()
                .WithImage(PostgreSqlImageName)
                .WithExposedPorts(PostgreSqlContainer.POSTGRESQL_PORT)
                .WithEnv(("POSTGRES_PASSWORD", "Password123"))
                .Build();

        public async Task StartAsync() => await _container.Start();
        public async Task StopAsync() => await _container.Stop();
    }

I am starting the test container via calling the constructor and calling StartAsync after that. Like this:

var fixture = new PostgreSqlFixture();
await fixture.StartAsync();

As soon as I start the container I am getting following error:

IntegrationInventory.Service.Tests.IntegrationTests.Services.BuyingPriceUpdaterServiceTests

System.MissingMethodException : Method not found: 'Polly.Timeout.TimeoutPolicy Polly.Policy.TimeoutAsync(System.TimeSpan)'.
TearDown : System.InvalidOperationException : Container must be started before mapped ports can be retrieved
   at TestContainers.Core.Containers.PostgreSqlContainer.WaitUntilContainerStarted()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at TestContainers.Core.Containers.PostgreSqlContainer.WaitUntilContainerStarted()
   at TestContainers.Core.Containers.Container.TryStart()
   at TestContainers.Core.Containers.Container.Start()
   at IntegrationInventory.Service.Tests.IntegrationTests.Fixtures.PostgreSqlFixture.StartAsync()

I can see the running container in Docker Desktop. But the code gives me error.

To Reproduce Steps to reproduce the behavior:

  1. Create a postgresql container.
  2. Call StartAsync.

Expected behavior I expect the container to be started.

Desktop (please complete the following information):

  • OS: macOS Catalina

dogac00 avatar Jan 13 '21 17:01 dogac00

I found the inner exception:

System.InvalidOperationException : Container must be started before mapped ports can be retrieved
TearDown : System.InvalidOperationException : Container must be started before mapped ports can be retrieved

What can we do to fix this?

dogac00 avatar Jan 13 '21 17:01 dogac00