Wait for readiness

This commit is contained in:
Adria Navarro 2023-05-11 20:32:44 +02:00
parent 32695018bf
commit fd18529135
1 changed files with 15 additions and 2 deletions

View File

@ -1,5 +1,8 @@
import { GenericContainer } from "testcontainers" import { GenericContainer } from "testcontainers"
import { Duration, TemporalUnit } from "node-duration"
import postgres from "../../../../packages/server/src/integrations/postgres" import postgres from "../../../../packages/server/src/integrations/postgres"
import { SourceName } from "@budibase/types"
jest.unmock("pg") jest.unmock("pg")
jest.unmock("mssql") jest.unmock("mssql")
@ -57,14 +60,24 @@ describe("datasource validators", () => {
let host: string, port: number let host: string, port: number
const password = "Str0Ng_p@ssW0rd!"
beforeAll(async () => { beforeAll(async () => {
const container = await new GenericContainer( const container = await new GenericContainer(
"mcr.microsoft.com/mssql/server" "mcr.microsoft.com/mssql/server"
) )
.withExposedPorts(1433) .withExposedPorts(1433)
.withEnv("ACCEPT_EULA", "Y") .withEnv("ACCEPT_EULA", "Y")
.withEnv("MSSQL_SA_PASSWORD", "Str0Ng_p@ssW0rd!") .withEnv("MSSQL_SA_PASSWORD", password)
.withEnv("MSSQL_PID", "Developer") .withEnv("MSSQL_PID", "Developer")
.withWaitStrategy(Wait.forHealthCheck())
.withHealthCheck({
test: `/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "${password}" -Q "SELECT 1" -b -o /dev/null`,
interval: new Duration(1000, TemporalUnit.MILLISECONDS),
timeout: new Duration(3, TemporalUnit.SECONDS),
retries: 20,
startPeriod: new Duration(100, TemporalUnit.MILLISECONDS),
})
.start() .start()
host = container.getContainerIpAddress() host = container.getContainerIpAddress()
@ -74,7 +87,7 @@ describe("datasource validators", () => {
it("test valid connection string", async () => { it("test valid connection string", async () => {
const result = await validator({ const result = await validator({
user: "sa", user: "sa",
password: "Str0Ng_p@ssW0rd!", password,
server: host, server: host,
port: port, port: port,
database: "master", database: "master",