Skip to content

Commit

Permalink
Added additional log based wait strategy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Felix Saurbier authored and stillya committed Mar 25, 2024
1 parent b3addf8 commit bd0c95d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
contextPath = defaultKeycloakContextPath
}
if genericContainerReq.Env[keycloakTlsEnv] != "" {
genericContainerReq.WaitingFor = wait.ForHTTP(contextPath).
genericContainerReq.WaitingFor = wait.ForAll(wait.ForHTTP(contextPath).
WithPort(keycloakHttpsPort).
WithTLS(true).
WithAllowInsecure(true)
WithAllowInsecure(true),
wait.ForLog("Running the server"))
} else {
genericContainerReq.WaitingFor = wait.ForHTTP(contextPath)
genericContainerReq.WaitingFor = wait.ForAll(wait.ForHTTP(contextPath),
wait.ForLog("Running the server"))
}
}

Expand Down

0 comments on commit bd0c95d

Please sign in to comment.