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

Closed
happyherp opened this issue Apr 29, 2024 · 2 comments · Fixed by #8842
Closed

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

happyherp opened this issue Apr 29, 2024 · 2 comments · Fixed by #8842
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**.

@illabefat
Copy link

Seems to be caused by this PR: #7714

eddumelendez added a commit that referenced this issue Jul 2, 2024
Currently, `waitingFor` takes precedence over `setWaitStrategy`. This was introduced with
 ContainerDef in 1dba8d1. This commit  uses `waitStrategy` defined in GenericContainer for both
methods `waitingFor` and `setWaitStrategy`.

Fixes #8578
lizhou1111 pushed a commit to lizhou1111/testcontainers-java that referenced this issue Jul 13, 2024
Currently, `waitingFor` takes precedence over `setWaitStrategy`. This was introduced with
 ContainerDef in 1dba8d1. This commit  uses `waitStrategy` defined in GenericContainer for both
methods `waitingFor` and `setWaitStrategy`.

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

Successfully merging a pull request may close this issue.

2 participants