yandex-qatools / postgresql-embedded

Embedded PostgreSQL Server
Other
494 stars 90 forks source link

Connection error on Windows during AppVeyor build #86

Open edrdo opened 7 years ago

edrdo commented 7 years ago

Hi,

I've been using postgresql-embedded for tests in JDBDT (http://github.com/edrdo/jdbdt) without any problems on MacOS and Linux. I was just trying to enable AppVeyor continuous integration for Windows builds when I encounted some errors.

The way I use postgresql-embedded is simple (full code here in https://github.com/edrdo/jdbdt/blob/master/src/test/java/org/jdbdt/postgresql/PostgreSQLSuite.java)

On setup I have:

  postgres = new EmbeddedPostgres(Version.V9_6_2);
  Path cachePath = FileSystems.getDefault().getPath(System.getProperty("user.home") + "/.embedpostgresql/");
  String url = postgres.start(EmbeddedPostgres.cachedRuntimeConfig(cachePath));

During a AppVeyor build - check https://ci.appveyor.com/project/edrdo/jdbdt/build/3 - the JDBC driver is unable to connect to the embedded Postgres database.

   org.postgresql.util.PSQLException: Connection to localhost:1047 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:265)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)

Maybe this is an Appveyor issue with restricted port use? In that case how can I configure the port for the "cached runtime config" . More generally, the point of the cached config is to avoid downloading the PostgreSQL binaries, but I gather that there is no way to set the URL parameters (name, pass, port, etc). I looked up the postgresql-embedded source code but I couldn't determine how to set up these together with a cached config, probably I'm missing something ...

edrdo commented 7 years ago

I solved my problem for now using AppVeyor's built-in Postgres service, bypassing the use of postgresql-embedded. I saw your README more carefully and became aware of quite a few issues on Windows, maybe you can close this issue. Out of curiosity anyway, I forked your repository temporarily and I noticed your AppVeyor build also fails (on the psexec step).

smecsia commented 7 years ago

@edrdo You're right, PostgreSQL (and therefore this library as well) has some limitations. The problem with Appveyor is that it runs builds under administrator by default and PostgreSQL cannot be started under privileged user. I tried to use psexec to force Appveyor to run builds under the limited user, but it was not successful.