testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
8.02k stars 1.65k forks source link

[Bug]: Cannot execute a stored proc inside test containers #7596

Closed MKaramen closed 1 year ago

MKaramen commented 1 year ago

Module

MSSQLServer

Testcontainers version

latest

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version

Docker version 24.0.5, build ced0996

What happened?

I've encountered a bug while working on my Micronaut application. This application needs to connect to an MSSQL Server (jdbc) and execute a stored procedures. The problem occurs specifically during testing when I'm using MicronautTest, Junit5, and Testcontainers.

To set up my testing environment, I've created an initialization script that restores a database with all the required data and the stored procedure. I've made sure that this script is executed before any test method runs. However, every time I attempt to test a method that calls the stored procedure, the test fails, consistently giving me the same error: "Could not find stored procedure"

I've gone through several troubleshooting steps to try and resolve this issue:

Verified that the database restoration script is executed before the first method call. Attempted to connect to the database inside the Docker container to confirm that everything is restored correctly and that the stored procedure exists. As a further experiment, I ran my application directly on the test container, and to my surprise, I encountered no issues. The stored procedure was found, and my methods executed without any errors.

Relevant log output

Caused by: org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call foo.bar(?)}]; SQL state [S0062]; error code [2812]; Could not find stored procedure 'foo.bar'.
    at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1581)

Additional Information

No response

eddumelendez commented 1 year ago

Hi @MKaramen, please consider adding a reproducer if you want us to spend time on it.

MKaramen commented 1 year ago

Found the issue, the stored procedures were executed with the database "master" by default instead of the one I restored.