whisklabs / docker-it-scala

Docker integration testing kit with Scala
MIT License
431 stars 91 forks source link

PostgresServiceSpec fails with driver libraries from 42 #126

Closed evbo closed 5 years ago

evbo commented 6 years ago

It appears that docker-it-scala in some cases fails to connect using postgres driver libraries 42.2.2 in my case. Here are my steps:

The failure is documented precisely here: https://github.com/whisklabs/docker-it-scala/issues/101

First, to verify something isn't wrong with my docker setup, I place a break point so that docker-it-scala starts the docker container but doesn't yet connect. This allows me to verify I can connect outside of the scala code.

Here's my breakpoint: https://github.com/whisklabs/docker-it-scala/blob/master/samples/src/main/scala/com/whisk/docker/DockerPostgresService.scala#L38

Then, I verify my container was created:

sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
6c7657440580        postgres:9.5.3      "/docker-entrypoint.…"   13 minutes ago      Up 13 minutes       0.0.0.0:44444->5432/tcp   vibrant_snyder

With that confirmed, I try to confirm that postgres is running correctly in the container:

sudo docker exec -it 6c7657440580 /bin/bash

root@6c7657440580:/# psql -h localhost -U nph -p 5432
psql (9.5.3)
Type "help" for help.

nph=# 

Now that I've confirmed I can connect locally, I download a simple JDBC commandline tool and the latest postgresql driver (that I'm using) and connect successfully:

java -cp lib/jisql.jar:lib/jopt-simple-3.2.jar:lib/postgresql-42.2.2.jar com.xigole.util.sql.Jisql -user nph -password suitup -driver postgresql -cstring jdbc:postgresql://127.0.0.1:44444/ -c \;

Enter a query:
1 > 

So this means that I can connect with a 42 postgres driver, but not so with docker-it-scala. Trying with docker-it-scala, I get the exceptions exactly as documented here: https://github.com/whisklabs/docker-it-scala/issues/101

I can fix this problem by downgrading my driver sbt dependency to: "org.postgresql" % "postgresql" % "9.4.1212", // "org.postgresql" % "postgresql" % "42.2.2",

clintfred commented 5 years ago

I was running into the same issue, but it was fixed by upgrading to 0.9.8

libraryDependencies ++= Seq(
  "com.whisk" %% "docker-testkit-scalatest" % "0.9.8" % "test",
  "com.whisk" %% "docker-testkit-impl-spotify" % "0.9.8" % "test")

I notice that the README still says 0.9.5. I will PR a README change to help others avoid this. @evbo Can you confirm this fixes the issue for you as well?