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

Cannot Open Connection to Docker From Gradle Test Suite #223

Open
SenorPez opened this issue Apr 13, 2023 · 1 comment
Open

Cannot Open Connection to Docker From Gradle Test Suite #223

SenorPez opened this issue Apr 13, 2023 · 1 comment

Comments

@SenorPez
Copy link

Expected Behavior

Connection should be made to Docker by Test Resources.

Actual Behaviour

When run from a Gradle Test Suite instead of the built-in test task, the test attempts to connect to 127.0.0.1:27017 instead of localhost:56559 (or another randomly generated port, depending on settings). This results in the following error and no further test progress as the Docker images aren't created or accessible.

com.mongodb.MongoSocketOpenException: Exception opening socket

Steps To Reproduce

Create a gradle build with an integration Test Suite.

testing {
    suites {
        withType(JvmTestSuite) {
            dependencies {
                implementation("org.assertj:assertj-core:3.24.2")

            }
        }
        test {
            useJUnitJupiter()
            dependencies {
                implementation('org.mockito:mockito-junit-jupiter:5.2.0')
                implementation("org.testcontainers:junit-jupiter")
                implementation("org.testcontainers:mongodb")
                implementation("org.testcontainers:testcontainers")
                implementation 'io.projectreactor:reactor-test:3.5.4'
            }
        }

        integrationTest(JvmTestSuite) {
            dependencies {
                implementation(project(project.path))

                implementation('com.networknt:json-schema-validator:1.0.78')
                implementation('io.micronaut.test:micronaut-test-junit5:3.9.2')
                implementation('io.micronaut:micronaut-http-client:3.8.7')
            }
        }
    }
}

Create a test that hits the database

    @Test
    void emptyDatabaseContainsNoDesigns() {
        HttpResponse<List<DesignModel>> response = designClient.get();
        assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);
        assertThat(response.getBody().isPresent()).isTrue();
        assertThat(response.getBody().get().size()).isEqualTo(0);
    }

The exact same test will properly start, pass, and close the test resources database in the test source set, and fail in the integrationTest source set.

Environment Information

  • Windows
  • Docker

Example Application

No response

Version

3.8.8

@melix
Copy link
Collaborator

melix commented Jul 11, 2023

Sorry for the late answer but could you provide a reproducer? From your configuration it seems that you are not using test resources, since you are adding dependencies on testcontainers itself, which shouldn't be the case if you are using test resources.

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

No branches or pull requests

2 participants