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

[Bug]: GenericContainer.waitingFor takes precedence over setWaitStrategy #8578

Open
happyherp opened this issue Apr 29, 2024 · 1 comment
Open
Labels

Comments

@happyherp
Copy link

Module

Core

Testcontainers version

1.19.7

Using the latest Testcontainers version?

Yes

Host OS

MacOs

Host Arch

ARM

Docker version

Docker version 20.10.14, build a224086

What happened?

We were previously using test-containers version 1.17.3.
When we switched to 1.19.7 some of our tests stopped working because the behaviour of GenericContainer.setWaitStrategy changed.

Our Code looked roughly like this:

postgreDBContainer = new PostgreSQLContainer<>(postgresImage).withExposedPorts(5432).withUsername("feature")
				.withPassword("xxx").withDatabaseName("xxx");
		postgreDBContainer.setWaitStrategy( 
				new LogMessageWaitStrategy().withRegEx(".*database system is ready to accept connections.*")
						.withTimes(1).withStartupTimeout(Duration.of(60, SECONDS)));

After the upgrade, the waitstrategy provided is no longer used.

I wrote a Test for this that can be copy-pasted into GenericContainerTest.java

    @Test
    public void shouldUseLatestWaitStrategy(){
        try (GenericContainer<?> container = new GenericContainer<>("testcontainers/helloworld:1.1.0")) {

            WaitForExitedState strategy1 = new WaitForExitedState(state -> false);
            WaitForExitedState strategy2 = new WaitForExitedState(state -> true);

            container.waitingFor(strategy1);
            container.setWaitStrategy(strategy2);
            assertThat(container.getWaitStrategy()).isEqualTo(strategy2);
        }
    }

I think the problem is because .waitingFor changes the field in GenericContainer, but setWaitStrategy changes it in GenericContainer.containerDef.

The PostgreSQLContainer-Constructor sets this.waitStrategy. After that it can no longer be changed by calling setWaitStrategy.

Relevant log output

No response

Additional Information

No response

@happyherp
Copy link
Author

Workaround: use .waitingFor instead of ** setWaitStrategy**.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant