testcontainers / testcontainers/testcontainers-scala

Issue while trying to use PostGis in testcontainer initialization.

Open
#263 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
668
Forks
136
PR merge metrics
No merged PRs in 30d

Description

Hi everyone. Please I need some assistance here. Recently I started a task in which I had to integrate PostGIS to the currently implemented test suite which uses testcontainers to validate DB transactions.

I started it by extending the PostgreSQLContainer to use the same container image as the PostgisSQLContainer class in testcontainers-java.

The code compiled, but when I ran the tests I started to get stack trace error messages like this one:

org.postgresql.util.PSQLException: ERROR: CREATE DATABASE cannot be executed within a pipeline at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2532) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2267) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:312) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:448) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:369) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:153) at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:142) at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)

I couldn't get a straight answer from Stackoverflow's search results regarding this error except that this is a safeguard. But, what I didn't get is why this was working before.

The apparently problematic script is the following:
` val dbCreateSQL =

      s"""|DO
          |'
          |BEGIN
          | IF NOT EXISTS (
          |         SELECT FROM pg_catalog.pg_roles
          |         WHERE  rolname = ''$userName'') THEN
          |
          |           CREATE ROLE $userName WITH SUPERUSER LOGIN PASSWORD ''$password'';
          | END IF;
          |
          |END
          |'
          |;
          |CREATE DATABASE $dbName WITH OWNER = $userName;
          |""".stripMargin
    withCloseable(sharedDBConnection.prepareStatement(dbCreateSQL)) { ps =>
      val _ = ps.execute()
    }`

Essentially, all I did was change this statement DockerImageName.parse("postgres:13.3") for this statement DockerImageName.parse("postgis/postgis").asCompatibleSubstituteFor("postgres").

I appreciate any insight you can provide me.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the test suite's PostgreSQLContainer setup and compare it with the PostgisSQLContainer usage in testcontainers-java. Reproduce the failure while running the database transaction tests, then trace the dbCreateSQL execution through sharedDBConnection. Done means the PostGIS-backed initialization completes without the reported CREATE DATABASE pipeline error.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, postgres, scala
Domain
databases, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.