Deffiss / testenvironment-docker

MIT License
117 stars 30 forks source link

Unable to use ElasticsearchContainer in the project with NEST version of 7.x #26

Closed vhatsura closed 4 years ago

vhatsura commented 4 years ago

The following exception is occurred during an attempt to bootstrap elasticsearch container in a project with 7.x NEST package:

System.TypeLoadException : Could not load type 'Nest.IClusterHealthResponse' from assembly 'Nest, Version=7.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.
   at TestEnvironment.Docker.Containers.Elasticsearch.ElasticsearchContainerWaiter.Wait(ElasticsearchContainer container, CancellationToken cancellationToken)
   at TestEnvironment.Docker.Containers.Elasticsearch.ElasticsearchContainerWaiter.Wait(Container container, CancellationToken cancellationToken)
   at TestEnvironment.Docker.Container.WaitForReadiness(CancellationToken token)
   at TestEnvironment.Docker.Container.Run(IDictionary`2 environmentVariables, CancellationToken token)
   at TestEnvironment.Docker.DockerEnvironment.Up(CancellationToken token)

The issue is in breaking changes in NEST package, namely:

https://github.com/Deffiss/testenvironment-docker/blob/2c1248bf4e22816253a28af5d5faa4afd3844646/src/TestEnvironment.Docker.Containers.Elasticsearch/ElasticsearchContainerWaiter.cs#L20-L24

in 7.x client, should be:

var health = await elastic.Cluster.HealthAsync(
                selector: ch => ch.WaitForStatus(WaitForStatus.Yellow).Level(Level.Cluster).ErrorTrace(true),
                ct: cancellationToken);

https://github.com/Deffiss/testenvironment-docker/blob/2c1248bf4e22816253a28af5d5faa4afd3844646/src/TestEnvironment.Docker.Containers.Elasticsearch/ElasticsearchContainerCleaner.cs#L19-L20

in 7.x client, should be:

await elastic.Indices.DeleteTemplateAsync("*", ct: token);
await elastic.Indices.DeleteAsync("*", ct: token);

I know updating the NEST package can be unreal, however, the ability to override cleaner and waiter for a container can solve the issue. It will allow using custom waiter with methods from the NEST 7.x package.

Deffiss commented 4 years ago

@vhatsura New version of the nuget package for Elasticsearch container has been published and soon be available. Please let me know if this fixes your problem.

vhatsura commented 4 years ago

@Deffiss, I'm afraid of it doesn't work with  TestEnvironment.Docker 1.3.4 due to https://github.com/Deffiss/testenvironment-docker/pull/19, which haven't been published yet.

System.AggregateException : One or more errors occurred. (Could not load type 'TestEnvironment.Docker.BaseContainerWaiter`1' from assembly 'TestEnviro...

System.AggregateException : One or more errors occurred. (Could not load type 'TestEnvironment.Docker.BaseContainerWaiter`1' from assembly 'TestEnvironment.Docker, Version=1.3.4.0, Culture=neutral, PublicKeyToken=null'.) (The following constructor parameters did not have matching fixture data: EnvironmentFixture environmentFixture)
---- System.TypeLoadException : Could not load type 'TestEnvironment.Docker.BaseContainerWaiter`1' from assembly 'TestEnvironment.Docker, Version=1.3.4.0, Culture=neutral, PublicKeyToken=null'.
Deffiss commented 4 years ago

Ok, got it. Thanks for letting that know. I'll publish immediately

Deffiss commented 4 years ago

New versions have been published. Soon they should become available. Please check and let us know.

vhatsura commented 4 years ago

@Deffiss, I can confirm that issue is resolved in TestEnvironment.Docker.Containers.Elasticsearch package of 1.1.6 version.

Thanks a lot