Skip to content

Commit

Permalink
test/e2e: increase timeout (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao authored Dec 9, 2024
1 parent 68ccaea commit ca780b0
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test: manifests generate fmt vet envtest ## Run tests.
.PHONY: test-e2e
SKAFFOLD_PROFILE ?= kustomize
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
SKAFFOLD_PROFILE=${SKAFFOLD_PROFILE} go test -timeout 20m -v ./test/e2e/ -run="^TestOperator/${TEST_RUN}"
SKAFFOLD_PROFILE=${SKAFFOLD_PROFILE} go test -timeout 20m -v ./test/e2e/ -run="^TestOperator/${TEST_RUN}" -parallel 4

.PHONY: kind-image
kind-image:
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,26 @@ func TestOperator(t *testing.T) {
ts.Fatalf("unexpected success")
}
},
// kubectl-wait-available runs kubectl wait for the given deployment available
"kubectl-wait-available": func(ts *testscript.TestScript, neg bool, args []string) {
if len(args) == 0 {
ts.Fatalf("usage: kubectl-wait-available <name>")
}
// wait for the deployment to be available,
// minimum available is 1 so pods are created
err = ts.Exec("kubectl", append([]string{"-n", ts.Getenv("NAMESPACE"),
"wait", "--for=condition=available",
// We need a timeout of 10m because we run the test in parallel
// and the controller-manager is not able to handle all the requests
// at the same time
"--timeout=10m",
}, args...)...)
if !neg {
ts.Check(err)
} else if err == nil {
ts.Fatalf("unexpected success")
}
},
// envfile read the file and using its content as environment variables
"envfile": func(ts *testscript.TestScript, neg bool, args []string) {
if neg {
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/testscript/migration-mysql.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/mysql
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=mysql pods

Expand All @@ -20,7 +23,7 @@ kubectl create configmap migration-dir --from-file=migrations-v2 --dry-run=clien
stdin stdout
kubectl apply -f -
# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=120s AtlasMigration/mysql
kubectl wait --for=condition=ready=false --timeout=500s AtlasMigration/mysql
kubectl-wait-ready AtlasMigration/mysql

# Inspect the schema to ensure it's correct
Expand All @@ -32,10 +35,10 @@ kubectl create configmap migration-dir --from-file=migrations-v1 --dry-run=clien
stdin stdout
kubectl apply -f -
# Expect migration is failured
kubectl wait --timeout=120s --for=jsonpath='{.status.conditions[*].message}'='"Migrate down is not allowed"' AtlasMigration/mysql
kubectl wait --timeout=500s --for=jsonpath='{.status.conditions[*].message}'='"Migrate down is not allowed"' AtlasMigration/mysql
# Patch the migration to allow down migration
kubectl patch AtlasMigration/mysql --type merge --patch-file ./migration-patch-down.yaml
kubectl wait --timeout=120s --for=condition=ready AtlasMigration/mysql
kubectl wait --timeout=500s --for=condition=ready AtlasMigration/mysql

# Inspect the schema to ensure it's correct after down migration
atlas schema inspect -u ${DB_URL} --exclude=atlas_schema_revisions
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/testscript/schema-clickhouse.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=clickhouse://root:pass@clickhouse.${NAMESPACE}:9000/myapp
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/clickhouse
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=clickhouse pods

Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-lint-destructive.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/mysql
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=mysql pods

Expand All @@ -18,7 +21,7 @@ kubectl patch -f schema.yaml --type merge --patch-file patch-remove-bio.yaml
exec sleep 10

# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=LintPolicyError --timeout=120s AtlasSchemas/mysql
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=LintPolicyError --timeout=500s AtlasSchemas/mysql
# Check the error message
kubectl get AtlasSchema/mysql -o jsonpath --template='{.status.conditions[*].message}'
stdout 'destructive changes detected:'
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-manual-changes.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand All @@ -27,7 +30,7 @@ atlas schema apply --auto-approve --url=${DB_URL} --dev-url=${DEV_URL} --to=file

kubectl patch -f schema.yaml --type merge --patch-file patch-comment.yaml
# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=120s AtlasSchemas/postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=500s AtlasSchemas/postgres

# Get the plan URL from resource then approve it
kubectl get AtlasSchemas/postgres -o go-template --template='{{ .status.planURL }}'
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-mariadb.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=mariadb://root:pass@mariadb.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/mariadb
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=mariadb pods

Expand Down Expand Up @@ -29,7 +32,7 @@ stdin stdout
kubectl apply -f -

# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=120s AtlasSchema/mariadb
kubectl wait --for=condition=ready=false --timeout=500s AtlasSchema/mariadb
kubectl-wait-ready AtlasSchema/mariadb

# Inspect the schema to ensure it's correct
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-mysql.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/mysql
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=mysql pods

Expand Down Expand Up @@ -29,7 +32,7 @@ stdin stdout
kubectl apply -f -

# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=120s AtlasSchema/mysql
kubectl wait --for=condition=ready=false --timeout=500s AtlasSchema/mysql
kubectl-wait-ready AtlasSchema/mysql

# Inspect the schema to ensure it's correct
Expand Down
7 changes: 5 additions & 2 deletions test/e2e/testscript/schema-plan-concurrently.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand All @@ -24,7 +27,7 @@ cmp stdout schema-v1.hcl

# Add a new index to the schema
kubectl patch -f schema.yaml --type merge --patch-file patch-index.yaml
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=120s AtlasSchemas/postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=500s AtlasSchemas/postgres

# Get the plan URL from resource
kubectl get AtlasSchemas/postgres -o go-template --template='{{ .status.planURL }}'
Expand All @@ -43,7 +46,7 @@ stdout '}'
atlas schema plan approve --url=${PLAN_URL}

# The migration should be failed
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApplyingSchema --timeout=120s AtlasSchemas/postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApplyingSchema --timeout=500s AtlasSchemas/postgres
# Check the error message
kubectl get AtlasSchemas/postgres -o jsonpath --template='{.status.conditions[*].message}'
stdout 'pq: CREATE INDEX CONCURRENTLY cannot run inside a transaction block'
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-plan-destructive.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand All @@ -24,7 +27,7 @@ cmp stdout schema-v1.hcl

kubectl patch -f schema.yaml --type merge --patch-file patch-remove-c1.yaml
# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=120s AtlasSchemas/postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=500s AtlasSchemas/postgres

# Get the plan URL from resource then approve it
kubectl get AtlasSchemas/postgres -o go-template --template='{{ .status.planURL }}'
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-plan-no-push.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand All @@ -27,7 +30,7 @@ cmp stdout schema-v1.hcl

kubectl patch -f schema.yaml --type merge --patch-file patch-remove-c1.yaml
# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=120s AtlasSchemas/postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=500s AtlasSchemas/postgres

# Get the plan URL from resource then approve it
kubectl get AtlasSchemas/postgres -o go-template --template='{{ .status.planURL }}'
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-plan-pre-approved.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand Down Expand Up @@ -32,7 +35,7 @@ cmp stdout schema-v1.hcl

kubectl patch -f schema.yaml --type merge --patch-file patch-remove-c1.yaml
# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=120s AtlasSchema/postgres
kubectl wait --for=condition=ready=false --timeout=500s AtlasSchema/postgres

# The schema should be updated now
kubectl-wait-ready AtlasSchemas/postgres
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/testscript/schema-policy-diff.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/mysql
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=mysql pods

Expand Down
3 changes: 3 additions & 0 deletions test/e2e/testscript/schema-postgres.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-registry.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand All @@ -24,7 +27,7 @@ cmp stdout schema-v1.hcl

kubectl patch -f schema.yaml --type merge --patch-file patch-v2.yaml
# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=120s AtlasSchema/postgres
kubectl wait --for=condition=ready=false --timeout=500s AtlasSchema/postgres
kubectl-wait-ready AtlasSchema/postgres

# Inspect the schema to ensure it's correct
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/testscript/schema-review-always.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl-wait-available deploy/postgres
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=postgres pods

Expand All @@ -17,7 +20,7 @@ plans-rm stdout
# Create the schema
kubectl apply -f schema.yaml
# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=120s AtlasSchemas/postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=500s AtlasSchemas/postgres

# Get the plan URL from resource then approve it
kubectl get AtlasSchemas/postgres -o go-template --template='{{ .status.planURL }}'
Expand Down
7 changes: 5 additions & 2 deletions test/e2e/testscript/schema-sqlserver.txtar
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
env DB_URL=sqlserver://sa:P%40ssw0rd0995@sqlserver.${NAMESPACE}:1433?database=master
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}

# Wait for the first pod created
kubectl wait --for=condition=available --timeout=600s deploy/sqlserver
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=420s -l app=sqlserver pods
kubectl wait --for=condition=ready --timeout=600s -l app=sqlserver pods

# Create the secret to store ATLAS_TOKEN
kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN}

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=420s AtlasSchema/sqlserver
kubectl wait --for=condition=ready --timeout=600s AtlasSchema/sqlserver

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
Expand Down

0 comments on commit ca780b0

Please sign in to comment.