title: Testcontainers mongodb - Cluster description not yet available. Waiting for 30000 ms before timing out
body: <p>I have basic <code>Spring</code> repository:</p>
  
  <pre><code>@Repository
  public interface LRepository extends MongoRepository&lt;L, String&gt; {}
  </code></pre>
  
  <p>And I am using it inside a service:</p>
  
  <pre><code>@Service
  @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  public class SerImpl {
      private final LRepository repository;
  
      public String saveL(L l) {
          l = repository.save(l);
          return l.id;
      }
  }
  </code></pre>
  
  <p>On line with <code>.save(l)</code> my test timeouts.</p>
  
  <pre><code>@SpringBootTest
  @ExtendWith(SpringExtension.class)
  @Testcontainers
  @ContextConfiguration(initializers = {MongoIntegrationTest.TestPropertiesInitializer.class})
  class MongoIntegrationTest {
      private SerImpl serImpl;
  
      @Autowired
      private LRepository lRepository;
  
      public static class TestPropertiesInitializer implements ApplicationContextInitializer&lt;ConfigurableApplicationContext&gt; {
          @Override
          public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
              final TestPropertyValues values = TestPropertyValues.of(
                      "spring.data.mongodb.host=localhost",
                      "spring.data.mongodb.username=root",
                      "spring.data.mongodb.password=example",
                      "spring.data.mongodb.authentication-database=admin",
                      "spring.data.mongodb.database=l",
                      "spring.data.mongodb.uri=mongodb://root:example@localhost:27017"
              );
              values.applyTo(configurableApplicationContext);
          }
      }
  
      @Container
      public GenericContainer mongoDb = new GenericContainer("mongo:4.2.2")
              .withExposedPorts(27017)
              .withEnv("MONGO_INITDB_ROOT_USERNAME", "root")
              .withEnv("MONGO_INITDB_ROOT_PASSWORD", "example");
  
      @BeforeEach
      public void setUp() {
          mongoDb.start();
  
          String address = mongoDb.getContainerIpAddress();
          //List&lt;Integer&gt; exposedPorts = mongoDb.getExposedPorts();
          Integer port = mongoDb.getFirstMappedPort();
          Map&lt;String,String&gt; map = mongoDb.getEnvMap();
          serImpl = new SerImpl(lRepository);
      }
  
      @Test
      public void testSimplePutAndGet() {
          String id = serImpl.saveL(new L("aaa"));
          assertNotNull(id);
      }
  }
  </code></pre>
  
  <p>On line <code>l = repository.save(l);</code></p>
  
  <p>I get an error saying</p>
  
  <blockquote>
  <pre><code>org.mongodb.driver.cluster     : Cluster description not yet available. Waiting for 30000 ms before timing out.
  </code></pre>
  </blockquote>
  
  <p>I tried to fix it by increasing timeout:</p>
  
  <pre><code>@Configuration
  public class MongoConfiguration {
      @Bean
      public MongoClientOptions mongoOptions() {
          return MongoClientOptions
                  .builder()
                  .serverSelectionTimeout(180000)
                  .build();
      }
  }
  </code></pre>
  
  <p>But more time did not help me here.
  <code>L</code> is object with <code>String</code> field.
  I simplified code above to make it more <strong>M</strong>VCE.
  When the test runs i see the container running and exposing the port.</p>
  
  <p>If i start mongo container from docker the test is successful.</p>
  
  <p>I am running it on Windows.</p>