Skip to content

Commit

Permalink
test: improve testcontainer test stability (#1011)
Browse files Browse the repository at this point in the history
By default, a DockerComposeContainer copies the full gradle project directory into container.
When running tests, the `build/test-results/test/binary/output.bin` file is written, which can get large.
This file is not required for the tests and the test container default is overwritten to a single file (i.e. `.env`)

Original error messages:
`org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker/compose`
`com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"unexpected EOF"}`
`java.io.IOException: Request to write '8192' bytes exceeds size in header of '2064381' bytes for entry`
  • Loading branch information
timonback authored Oct 11, 2024
1 parent 5a98efd commit 9cd9410
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ApiSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withExposedService(APP_NAME, APP_PORT)
.waitingFor(APP_NAME, Wait.forLogMessage(".*AsyncAPI document was built.*", 1))
.withEnv(ENV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ProducerSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withServices(AMQP_NAME)
.waitingFor(AMQP_NAME, Wait.forLogMessage(".*Server startup complete.*", 1))
.withLogConsumer(AMQP_NAME, l -> log.debug("amqp: {}", l.getUtf8StringWithoutLineEnding()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ApiSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withExposedService(APP_NAME, APP_PORT)
.waitingFor(APP_NAME, Wait.forLogMessage(".*AsyncAPI document was built.*", 1))
.withEnv(ENV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ApiSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withExposedService(APP_NAME, APP_PORT)
.waitingFor(APP_NAME, Wait.forLogMessage(".*AsyncAPI document was built.*", 1))
.withEnv(ENV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ProducerSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withServices(APP_JMS)
.withLogConsumer(APP_JMS, l -> log.debug("jms: {}", l.getUtf8StringWithoutLineEnding()))
.waitingFor(APP_JMS, Wait.forLogMessage(".*Artemis Console available.*", 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ApiSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withExposedService(APP_NAME, APP_PORT)
.waitingFor(APP_NAME, Wait.forLogMessage(".*AsyncAPI document was built.*", 1))
.withEnv(ENV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class ProducerSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withServices(KAFKA_NAME, USE_SCHEMA_REGISTRY ? "kafka-schema-registry" : "")
.withLogConsumer(KAFKA_NAME, l -> log.debug("kafka: {}", l.getUtf8StringWithoutLineEnding()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ApiSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withExposedService(APP_NAME, APP_PORT)
.waitingFor(APP_NAME, Wait.forLogMessage(".*AsyncAPI document was built.*", 1))
.withEnv(ENV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ApiSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withExposedService(APP_NAME, APP_PORT)
.waitingFor(APP_NAME, Wait.forLogMessage(".*AsyncAPI document was built.*", 1))
.withEnv(ENV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class ProducerSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withEnv(ENV)
.withServices(LOCALSTACK_NAME)
.withLogConsumer(LOCALSTACK_NAME, l -> log.debug("localstack: {}", l.getUtf8StringWithoutLineEnding()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ApiSystemTest {

@Container
public static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withCopyFilesInContainer(".env") // do not copy all files in the directory
.withExposedService(APP_NAME, APP_PORT)
.waitingFor(APP_NAME, Wait.forLogMessage(".*AsyncAPI document was built.*", 1))
.withEnv(ENV)
Expand Down

0 comments on commit 9cd9410

Please sign in to comment.