db2rest icon indicating copy to clipboard operation
db2rest copied to clipboard

Make MS SQLServer tests and connection handling more robust

Open thadguidry opened this issue 1 year ago • 1 comments

Sometimes during local testing, there is not enough of some kind of delay, in order to ensure that the MS SQLServer container is started, and the port and connection are available to use.

Warnings that should not be happening during testing:

2024-11-12T15:28:41.493+08:00  WARN 37996 --- [ main]
c.m.s.j.internals.SQLServerConnection    : 
ConnectionID:1 ClientConnectionId: e7f921ad-98a5-460e-8e9d-dffb9568e097
Prelogin error: host localhost port 51760
Unexpected end of prelogin response after 0 bytes read

Generally, we should make the Connection handling more robust and expect that sometimes there are delays reaching DB instances or containers due to intermittent networking issues.

For example, if during testing, there is no login actually needed, or it's implied or configured somehow, then we should ensure that it works without throwing these kinds of errors.

thadguidry avatar Nov 12 '24 07:11 thadguidry

2024-11-12T15:44:33.834+08:00  INFO 29900 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 0 (http)
2024-11-12T15:44:33.834+08:00  INFO 29900 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-11-12T15:44:33.834+08:00  INFO 29900 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.28]
2024-11-12T15:44:33.850+08:00  INFO 29900 --- [           main] o.a.c.c.C.[Tomcat-10].[localhost].[/]    : Initializing Spring embedded WebApplicationContext
2024-11-12T15:44:33.850+08:00  INFO 29900 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 229 ms
2024-11-12T15:44:33.868+08:00  INFO 29900 --- [           main] t.m.m.com/mssql/server:2022-latest       : Creating container for image: mcr.microsoft.com/mssql/server:2022-latest
2024-11-12T15:44:34.046+08:00  INFO 29900 --- [           main] o.t.utility.RegistryAuthLocator          
: Credential helper/store (docker-credential-desktop) does not have credentials for mcr.microsoft.com    
2024-11-12T15:44:34.104+08:00  INFO 29900 --- [           main] t.m.m.com/mssql/server:2022-latest       : Container mcr.microsoft.com/mssql/server:2022-latest is starting: 51453c2a7b6401eed334e30313f9af1b1bf7640e65c57cd6fd150e29a71c3b24
2024-11-12T15:44:34.398+08:00  INFO 29900 --- [           main] t.m.m.com/mssql/server:2022-latest       : Waiting for database connection to become available at jdbc:sqlserver://localhost:53304 using query 'SELECT 1'
2024-11-12T15:44:34.446+08:00  WARN 29900 --- [           main] c.m.s.j.internals.SQLServerConnection    : ConnectionID:1 ClientConnectionId: 0327816d-06ec-452d-bafd-e30588eed849 Prelogin error: host localhost port 53304 Unexpected end of prelogin response after 0 bytes read

Upon further investigation, it seems that SOMETIMES, the port that the container is created with is 0:1433 and other times it's something else like 53304 as shown in 4th to last line above? So what happens is a long timeout as expected.

We should look into figuring out why the MS SQLServer port for the container isn't consistent when a run with mvn verify is done that is testing against all the containers.

  • Maybe it might even be better to close the container resources AFTER each DB test suite it done, instead of closing them all at once after all tests have finished? Maybe that will get rid of the intermittent non-avail port for MS SQLServer testcontainer?

thadguidry avatar Nov 12 '24 07:11 thadguidry