Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few tests are not stable in combination of Windows OS + Docker #484

Closed
vlaskal opened this issue Jun 21, 2022 · 5 comments
Closed

Few tests are not stable in combination of Windows OS + Docker #484

vlaskal opened this issue Jun 21, 2022 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@vlaskal
Copy link
Contributor

vlaskal commented Jun 21, 2022

Describe the bug
When development environment consist from:

  • Windows OS
  • Docker Desktop or Rancher Desktop
  • WSL

Then following tests fail

  • TestcontainersContainerTest.GetAuthConfig
  • CouchDbTestcontainerTest.ExecScriptInRunningContainer
  • KafkaTestcontainerTest.StartsWorkingKafkaInstance

Or is unstable when all tests are executed

  • TestcontainersContainerTest+WithConfiguration.WaitStrategy

To Reproduce
Steps to reproduce the behavior:

  1. Use Windows OS
  2. Use Docker Desktop or Rancher Desktop
  3. Run all tests in repository (Windows container test are skipped)
  4. Following tests fail
  • TestcontainersContainerTest.GetAuthConfig
  • CouchDbTestcontainerTest.ExecScriptInRunningContainer
  • KafkaTestcontainerTest.StartsWorkingKafkaInstance
  • TestcontainersContainerTest+WithConfiguration.WaitStrategy

Expected behavior
All tests should pass on first run

Desktop (please complete the following information):

  • Windows 11
  • Docker Desktop or Rancher Desktop
  • WSL
  • Git: core.autocrlf = false
@vlaskal
Copy link
Contributor Author

vlaskal commented Jun 21, 2022

Test: TestcontainersContainerTest.GetAuthConfig
Root cause of failure:
Expected docker endpoint value is unix:/var/run/docker.sock
but Windows OS with WSL is npipe://./pipe/docker_engine

I see two ways how to solve it:

  1. Add conditon which endpoint should be expected based on OS and Docker server version
  2. Create a new set of tests to cover this combination of OS + Docker. There are two sets fro pure Unix container on Linux based OS and Windows containers on Windows OS.

Which approach is better?

@vlaskal
Copy link
Contributor Author

vlaskal commented Jun 21, 2022

Test: CouchDbTestcontainerTest.ExecScriptInRunningContainer
Root cause of failure: Following script fails on creation database (first) command and response.ExistCode is 0.

 const string script = @"
        #!/bin/bash
        curl -v -X PUT http://couchdb:couchdb@127.0.0.1:5984/mydatabase/
        curl -v -X PUT http://couchdb:couchdb@127.0.0.1:5984/mydatabase/""001"" -d '{""name"":""MyName""}'
      ";

Behavior of this script depends on end of line characters.
If it is \n then the script works as expected but \r\n fails on creation database.

I see fix in ensuring that the command will try replace \r\n to just \n.

 const string script = @"
        #!/bin/bash
        curl -v -X PUT http://couchdb:couchdb@127.0.0.1:5984/mydatabase/
        curl -v -X PUT http://couchdb:couchdb@127.0.0.1:5984/mydatabase/""001"" -d '{""name"":""MyName""}'
      ".Replace("\r\n", "\n");

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Jun 22, 2022

  • DotNet.Testcontainers.Tests.Unit.Containers.Unix.TestcontainersContainerTest.WithConfiguration.GetAuthConfig:
    • Indeed, this test doesn't make much sense on Windows. The DockerEndpointAuthenticationProvider tests are a bit tricky, they rely on the host that runs the tests. E.g. if DOCKER_HOST is set, they will fail too. Probably, it's better to move the tests to DockerEndpointAuthenticationProviderTest and just test the implementation (hard-code) without calling DockerEndpointAuthenticationProvider().GetAuthConfig().
  • DotNet.Testcontainers.Tests.Unit.CouchDbTestcontainerTest.ExecScriptInRunningContainer:
    • Good catch. We can replace it with (maybe we can overload ExecScriptAsync in the future):
    const char lf = '\n';
    var script = new StringBuilder();
    script.Append("#!/bin/sh");
    script.Append(lf);
    script.Append("curl -v -X PUT http://couchdb:couchdb@127.0.0.1:5984/mydatabase/");
    script.Append(lf);
    script.Append("curl -v -X PUT http://couchdb:couchdb@127.0.0.1:5984/mydatabase/\"001\" -d '{\"name\":\"MyName\"}'");
  • DotNet.Testcontainers.Tests.Unit.Containers.Unix.TestcontainersContainerTest.WithConfiguration.WaitStrategy:
    • What error do you get?
  • DotNet.Testcontainers.Tests.Unit.KafkaTestcontainerTest.StartsWorkingKafkaInstance:
diff --git a/src/Testcontainers/Clients/TestcontainersConfigurationConverter.cs b/src/Testcontainers/Clients/TestcontainersConfigurationConverter.cs
index b75997b..d0cab90 100644
--- a/src/Testcontainers/Clients/TestcontainersConfigurationConverter.cs
+++ b/src/Testcontainers/Clients/TestcontainersConfigurationConverter.cs
@@ -148,7 +148,7 @@ namespace DotNet.Testcontainers.Clients
       public override IEnumerable<KeyValuePair<string, IList<PortBinding>>> Convert([CanBeNull] IEnumerable<KeyValuePair<string, string>> source)
       {
         return source?.Select(portBinding => new KeyValuePair<string, IList<PortBinding>>(
-          GetQualifiedPort(portBinding.Key), new[] { new PortBinding { HostPort = "0".Equals(portBinding.Value, StringComparison.Ordinal) ? null : portBinding.Value } }));
+          GetQualifiedPort(portBinding.Key), new[] { new PortBinding { HostPort = portBinding.Value } }));
       }
     }
   }

@HofmeisterAn HofmeisterAn added the bug Something isn't working label Jun 22, 2022
@HofmeisterAn HofmeisterAn added this to the 2.1.0 milestone Jun 22, 2022
@vlaskal
Copy link
Contributor Author

vlaskal commented Jun 22, 2022

DotNet.Testcontainers.Tests.Unit.Containers.Unix.TestcontainersContainerTest.WithConfiguration.WaitStrategy:

  • What error do you get?

I am getting Timeout exception.
Alone test goes fine, only stuck with all test together.

PS: Nice that you look at it.

@HofmeisterAn
Copy link
Collaborator

Published in 2.1.0-beta.2561986470.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants