stillya / testcontainers-keycloak

A Testcontainers implementation for Keycloak SSO.
MIT License
4 stars 4 forks source link

Added additional log based wait strategy #3

Closed flxsrbr closed 4 months ago

flxsrbr commented 4 months ago

Starting with Keycloak 24.0, initial imports of realm data from a json files seem to take longer. This can lead to tests starting before the imported realm is properly initialized and subsequent errors. The current ForHTTP strategy does not seem to ensure proper realm initialization. Therefore this PR proposes an additional wait strategy based on the final log line "Running the server" indicating the finalization of the startup process.

stillya commented 4 months ago

@flxsrbr, that's LGTM. Thanks for your contribution. I can make a guess that imports of Realm take a long time because we're mounting the directory instead of copying it into the container. However, I fixed this issue here, so in the nearest release, both fixes will be included.

flxsrbr commented 4 months ago

@stillya Thanks for the merge. The switch to copying instead of mounting sounds good. Interestingly, the realm import itself was still very fast in my case, as I only imported a very small realm.json file. But after updating to the Keycloak v24.0 image I ran into errors indicating that the realm I imported was not properly initialized - although the Keycloak endpoint was ready and i could get the admin client from the master realm. But getting a client from the imported realm resulted in an nil response. If I added a short delay (5 seconds) though, the error did not occur. So I think there must be some change in the process, speed, and/or order of spinning up the keycloak api and the realm import process. Esentially, the api endpoint seems to be available before the realm import is completed. But I did not research this further and could not find anything in the Keycloak release notes for 24.0 about this.