Fix occasional stale volume in postgres tests

Fixes #1522
This commit is contained in:
Dave Syer 2024-10-14 15:29:49 +01:00
parent 300597fc6c
commit 3b90fac983
3 changed files with 5 additions and 9 deletions

View file

@ -64,16 +64,16 @@ docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES
Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt) Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt)
and [PostgreSQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/postgres/petclinic_db_setup_postgres.txt). and [PostgreSQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/postgres/petclinic_db_setup_postgres.txt).
Instead of vanilla `docker` you can also use the provided `docker-compose.yml` file to start the database containers. Each one has a profile just like the Spring profile: Instead of vanilla `docker` you can also use the provided `docker-compose.yml` file to start the database containers. Each one has a service named after the Spring profile:
```bash ```bash
docker-compose --profile mysql up docker compose up mysql
``` ```
or or
```bash ```bash
docker-compose --profile postgres up docker compose up postgres
``` ```
## Test Applications ## Test Applications

View file

@ -11,8 +11,6 @@ services:
- MYSQL_DATABASE=petclinic - MYSQL_DATABASE=petclinic
volumes: volumes:
- "./conf.d:/etc/mysql/conf.d:ro" - "./conf.d:/etc/mysql/conf.d:ro"
profiles:
- mysql
postgres: postgres:
image: postgres:17.0 image: postgres:17.0
ports: ports:
@ -21,5 +19,3 @@ services:
- POSTGRES_PASSWORD=petclinic - POSTGRES_PASSWORD=petclinic
- POSTGRES_USER=petclinic - POSTGRES_USER=petclinic
- POSTGRES_DB=petclinic - POSTGRES_DB=petclinic
profiles:
- postgres

View file

@ -49,7 +49,7 @@ import org.springframework.web.client.RestTemplate;
import org.testcontainers.DockerClientFactory; import org.testcontainers.DockerClientFactory;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.docker.compose.skip.in-tests=false", // @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.docker.compose.skip.in-tests=false", //
"spring.docker.compose.profiles.active=postgres" }) "spring.docker.compose.start.arguments=--force-recreate,--renew-anon-volumes,postgres" })
@ActiveProfiles("postgres") @ActiveProfiles("postgres")
@DisabledInNativeImage @DisabledInNativeImage
public class PostgresIntegrationTests { public class PostgresIntegrationTests {
@ -72,7 +72,7 @@ public class PostgresIntegrationTests {
new SpringApplicationBuilder(PetClinicApplication.class) // new SpringApplicationBuilder(PetClinicApplication.class) //
.profiles("postgres") // .profiles("postgres") //
.properties( // .properties( //
"spring.docker.compose.profiles.active=postgres" // "spring.docker.compose.start.arguments=postgres" //
) // ) //
.listeners(new PropertiesLogger()) // .listeners(new PropertiesLogger()) //
.run(args); .run(args);