zonkyio / embedded-database-spring-test

A library for creating isolated embedded databases for Spring-powered integration tests.
Apache License 2.0
399 stars 37 forks source link

Database Initialization issues, can't find postgres binary #213

Closed RicardoMonteiroSimoes closed 1 year ago

RicardoMonteiroSimoes commented 1 year ago

Hello,

First of all, thank you for having these open source solutions. They're excellent and quite helpful. I am trying to get my current project to work on a Mac M1, and was able to solve most issues. The one I'm currently facing involves embedded-database-spring-test.

The current version that is being used is io.zonky.test:embedded-database-spring-test:1.6.3, and we would like to upgrade in the near future, but 2.x introduces breaking changes that we'd have to solve (and are somewhat absent from the upgrade guide?). Anyway, as I am sitting on arm64 platform, I upgraded io.zonky.test.postgres:embedded-postgres-binaries-bomto 15:0.0, which according to the gradle log, and my console output, downloads all the possible binaries:

embedded-postgres-binaries-bom
embedded-postgres-binaries-darwin-amd64
embedded-postgres-binaries-darwin-arm64v8
embedded-postgres-binaries-linux-amd64
embedded-postgres-binaries-linux-amd64-alpine
embedded-postgres-binaries-windows-amd64

Now, whenever I start running my tests, they fail. To be precise, they fail using an initializationError, which is cause by it not finding the correct binary:

2022-10-27T13:37:10,184 ERROR [    Test worker] [.DefaultPostgresBinaryResolver] No postgres binaries were found, you must add an appropriate maven dependency that meets the following parameters - system: Darwin, architecture: arm_64
2022-10-27T13:37:10,201 ERROR [    Test worker] [ice.RsmFlywayDataSourceContext] Failed to set up test DB

I assume it might be because it's looking for darwin-arm64 but it can only find darwin-arm64v8, but can't confirm it_

Any way, this of course leads to it failing and therefor not passing. What I can say is that on a linux OS machine, the project can test without any issue using io.zonky.test.postgres:embedded-postgres-binaries-bom:11.9.0.

So I assumed that this might be an issue involving macOS - according to my research, gradle cached files are saved on the same spot as they would be under linux, so that shouldn't be the issue. (I don't even know where it tries to find the binaries, so theres that).

SergeyAblaev commented 1 year ago

I have some problems too! I think that needed move test configuration from embedded postgres to docker tests for mac M1

RicardoMonteiroSimoes commented 1 year ago

The issues seems to be that some older zonkyio (anything pre 2) cannot correctly get the naming of the binaries, but I might be wrong.

tomix26 commented 1 year ago

Hi @RicardoMonteiroSimoes.

The naming conventions of the binaries haven't changed since the beginning of the project, so that's not the problem. The system: Darwin, architecture: arm_64 parameters are also correct.

The most likely cause of the problem are missing binaries. The dependency containing ARM binaries is not included by default, it must be added explicitly. Specifying a BOM file is not enough, it is only for managing the same versions.

So are you sure you added this dependency correctly? What type of dependency management system are you using? Maven, Gradle or something else? Can you attach an example?

Here are more details about enabling additional architectures: https://github.com/zonkyio/embedded-postgres#additional-architectures

tomix26 commented 1 year ago

What issues have you faced during the upgrade that are not described in the upgrade guide? https://github.com/zonkyio/embedded-database-spring-test/wiki/Embedded-Database-2.0-Release-Notes#upgrading-from-embedded-database-1x

RicardoMonteiroSimoes commented 1 year ago

The most likely cause of the problem are missing binaries. The dependency containing ARM binaries is not included by default, it must be added explicitly. Specifying a BOM file is not enough, it is only for managing the same versions.

Ah, that was the mistake. Was under the impression that the BOM included all Binaries, which is only the case for AMD64. After adding the ARM one the error went away.

Right now, even after clearing the var/folders/... temporary data, it fails to initialize the database.

java.lang.IllegalStateException: Process [/var/folders/_v/wp04d1994sd2tvqr3w14k5t40000gp/T/embedded-pg/PG-66d16f7b5fc12f5fc27ced9cf1b4c8e8/bin/initdb, -A, trust, -U, postgres, -D, /var/folders/_v/wp04d1994sd2tvqr3w14k5t40000gp/T/epg8352490524182623772, -E, UTF-8] failed
    at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:632)

Not sure what this could be about

What issues have you faced during the upgrade that are not described in the upgrade guide?

Up until now I extended the DefaultFlywayDataSourceContext, which of course is gone with v2+. It's replacement isn't quite clear to me - there are mentions of classes being moved/refactored, but that's about it.

tomix26 commented 1 year ago

Right now, even after clearing the var/folders/... temporary data, it fails to initialize the database.

Could you please attach the log file for further investigation?

Up until now I extended the DefaultFlywayDataSourceContext, which of course is gone with v2+. It's replacement isn't quite clear to me - there are mentions of classes being moved/refactored, but that's about it.

This is a low level internal API, so I didn't expect that anyone would need to extend this class. But if you think it might be useful, feel free to open a separate issue for that.

tomix26 commented 1 year ago

Or just join this one #216

RicardoMonteiroSimoes commented 1 year ago

Or just join this one #216

Yup, that one is basically the same.