I am trying to set up github CI workflow to do my springboot application tests. However the test are failing on database connection, even though locally it works fine.
The CI job is as follow
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3
- name: Prepare test database
run: docker-compose -f docker-compose-test.yaml up -d
- name: Wait for the database to start
run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- localhost:55001 -- echo "Database is up"
env:
WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Make gradlew executable
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
Docker compose test
services:
db-test-database:
image: mysql:5.5
ports:
- "55001:3306"
environment:
- MYSQL_ROOT_PASSWORD=my-secret-pw
- MYSQL_DATABASE=dbTest
- MYSQL_USER=root
- MYSQL_PASSWORD=my-secret-pw
To configure the database within tests I use projectroot/test/resources/application.yml
spring:
datasource:
url: jdbc:mysql://localhost:55001/dbTest
username: root
password: my-secret-pw
driver-class-name: com.mysql.cj.jdbc.Driver
But the smoke test (@SpringBootTest with autowire) fails on, suggesting not being able to connect to the database:
AppSmokeTest > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:98
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1804
Caused by: javax.persistence.PersistenceException at AbstractEntityManagerFactoryBean.java:421
Caused by: org.hibernate.exception.JDBCConnectionException at SQLStateConversionDelegate.java:112
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:174
Caused by: com.mysql.cj.exceptions.CJCommunicationsException at NativeConstructorAccessorImpl.java:-2
Caused by: java.net.ConnectException at Net.java:-2
Could anyone point me to what might be wrong?