Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres TestContainer fails with "No suitable driver found" when switching test profiles #14829

Closed
patrick-vonsteht opened this issue Feb 4, 2021 · 3 comments · Fixed by #14956
Labels
area/testing kind/bug Something isn't working
Milestone

Comments

@patrick-vonsteht
Copy link

Describe the bug
Setup:

  • You have two QuarkusTests
  • The QuarkusTests use different TestProfiles.
  • Both QuarkusTests start a postgres container through a QuarkusTestResourceLifecycleManager.

Expected behavior
Expected Result:

  • Both tests run successfully.

Actual behavior
Result:

  • The first test runs successfully.
  • The second test, after the profile switch, fails with "java.sql.SQLException: No suitable driver found for <SOME_JDBC_URL>"

To Reproduce

See minimal example at https://github.com/patrick-vonsteht/quarkus-test-containers-test-profiles-switch-bug

Steps to reproduce the behavior:

  1. Run "mvn test" in the reproducer.

Environment (please complete the following information):

  • Output of uname -a or ver: Microsoft Windows [Version 10.0.19042.746]
  • Output of java -version: openjdk version "11" 2018-09-25
    OpenJDK Runtime Environment 18.9 (build 11+28)
    OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
  • Quarkus version or git rev: 1.11.1.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)

Additional context
A similar issue has been fixed here: #12116

@patrick-vonsteht patrick-vonsteht added the kind/bug Something isn't working label Feb 4, 2021
@ghost ghost added the env/windows Impacts Windows machines label Feb 4, 2021
@gsmet
Copy link
Member

gsmet commented Feb 4, 2021

/cc @geoand

@geoand geoand added area/testing and removed env/windows Impacts Windows machines labels Feb 4, 2021
@geoand
Copy link
Contributor

geoand commented Feb 5, 2021

I'll take a look next week

geoand added a commit to geoand/quarkus that referenced this issue Feb 5, 2021
This fix is pretty terrible, but I don't see any other way around
the problem

Fixes: quarkusio#14829
geoand added a commit to geoand/quarkus that referenced this issue Feb 5, 2021
This fix is pretty terrible, but I don't see any other way around
the problem

Fixes: quarkusio#14829
stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Feb 10, 2021
stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Feb 10, 2021
stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Feb 10, 2021
@ghost ghost added this to the 1.12 - master milestone Feb 10, 2021
@matjazs
Copy link

matjazs commented Mar 22, 2021

I have only recently updated our Quarkus dependencies and found out that loading postgresql driver parent-first, causes our previously working, Postgis related, @QuarkusTest-annotated tests to fail.

Our test methods are failing when comparing:

  • instances of org.postgis.PGgeometry loaded from database within the same test method using the JDBC ResultSet and the injected Agroal data source, to
  • equal instances of org.postgis.PGgeometry instantiated within the same test method using a constructor.

PGgeometry comes from the net.postgis:postgis-jdbc:2.5.0 which is a PostGIS JDBC Driver extension.

The assertion errors look like:

java.lang.AssertionError:
Expecting:
  <...some org.postgis.PGgeometry instance...>
to be of class
  <org.postgis.PGgeometry>
but was of class
  <org.postgis.PGgeometry>

The actual difference are the class loaders being used to load the org.postgis.PGgeometry class:

  • the class loader referenced in org.postgresql.jdbc.PgConnection (JDBC connection obtained in test methods from the injected AgroalDataSource) is: ClassLoaders$AppClassLoader
  • the class loader used in test method thread is: QuarkusClassLoader:Quarkus Base Runtime ClassLoader

PgConnection has a type cache, containing the PG type name to Java class mappings. This type cache is used in PgConnection#getObject() for constructing org.postgis.PGgeometry instances when reading the data from ResultSets in our test methods. In our case the Java classes for the mappings are loaded with the ClassLoaders$AppClassLoader, resulting in a class loader mismatch when comparing them to PGgeometry instances created in the same test methods using a constructor.

We also use the Quarkus Flyway extension which causes to create a database connection prior to running the tests.

Is such behaviour anticipated and should we refactor our tests, or might this actually be a an issue? The tests work if I remove the parentFirstArtifacts configuration from extensions/jdbc/jdbc-postgresql/runtime/pom.xml. I can provide a reproducer if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
4 participants