Skip to content

Commit 3a5bdc8

Browse files
authored
acc: invariant: support init/cleanup scripts; fix synced_database_table (#4364)
## Changes - Extend invariant tests to allow custom init/cleanup scripts. - Use that to create unique source table to avoid "20 tables" limit on cloud. Same fix as #4329 - Ignore_remote_changes for synced_database_tables fields: database_instance_name and database_instance_name (not set by the backend, cause drift). - Ignore_remote_changes for database_catalog.create_database_if_not_exists (not set by the backend, cause drift). ## Why Fixes invariant/no_drift test for synced_database_tables and database_catalogs.
1 parent 6c0f55d commit 3a5bdc8

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

acceptance/bundle/invariant/configs/synced_database_table.yml.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ resources:
2020
database_instance_name: ${resources.database_instances.instance1.name}
2121
logical_database_name: ${resources.database_catalogs.catalog1.database_name}
2222
spec:
23-
source_table_full_name: samples.nyctaxi.trips
23+
# Use a unique source table per test run to avoid hitting the 20-table-per-source limit
24+
source_table_full_name: main.test_synced_$UNIQUE_NAME.trips_source
2425
scheduling_policy: SNAPSHOT
2526
primary_key_columns:
2627
- tpep_pickup_datetime
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Clean up the temporary source table
4+
echo "Cleaning up temporary source table"
5+
$CLI tables delete main.test_synced_$UNIQUE_NAME.trips_source || true
6+
$CLI schemas delete main.test_synced_$UNIQUE_NAME || true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Create a unique source table for this test run to avoid hitting the 20-table-per-source limit
4+
echo "Creating temporary source table: main.test_synced_$UNIQUE_NAME.trips_source"
5+
6+
# Create schema using CLI
7+
$CLI schemas create test_synced_$UNIQUE_NAME main -o json | jq '{full_name}'
8+
9+
# Create source table from samples.nyctaxi.trips using SQL API
10+
# MSYS_NO_PATHCONV=1 prevents Git Bash on Windows from converting /api/... to C:/Program Files/Git/api/...
11+
MSYS_NO_PATHCONV=1 $CLI api post "/api/2.0/sql/statements/" --json "{
12+
\"warehouse_id\": \"$TEST_DEFAULT_WAREHOUSE_ID\",
13+
\"statement\": \"CREATE TABLE main.test_synced_$UNIQUE_NAME.trips_source AS SELECT * FROM samples.nyctaxi.trips LIMIT 10\",
14+
\"wait_timeout\": \"45s\"
15+
}" > /dev/null

acceptance/bundle/invariant/no_drift/script

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
# Copy data files to test directory
55
cp -r "$TESTDIR/../data/." . &> LOG.cp
66

7+
# Run init script if present
8+
INIT_SCRIPT="$TESTDIR/../configs/$INPUT_CONFIG-init.sh"
9+
if [ -f "$INIT_SCRIPT" ]; then
10+
source "$INIT_SCRIPT" &> LOG.init
11+
fi
12+
713
envsubst < $TESTDIR/../configs/$INPUT_CONFIG > databricks.yml
814

915
cp databricks.yml LOG.config
@@ -16,6 +22,12 @@ cat LOG.validate | contains.py '!panic' '!internal error' > /dev/null
1622
cleanup() {
1723
trace $CLI bundle destroy --auto-approve &> LOG.destroy
1824
cat LOG.destroy | contains.py '!panic' '!internal error' > /dev/null
25+
26+
# Run cleanup script if present
27+
CLEANUP_SCRIPT="$TESTDIR/../configs/$INPUT_CONFIG-cleanup.sh"
28+
if [ -f "$CLEANUP_SCRIPT" ]; then
29+
source "$CLEANUP_SCRIPT" &> LOG.cleanup
30+
fi
1931
}
2032

2133
trap cleanup EXIT

acceptance/bundle/invariant/test.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ EnvMatrix.INPUT_CONFIG = [
3535
"synced_database_table.yml.tmpl",
3636
"volume.yml.tmpl",
3737
]
38+
39+
# Fake SQL endpoint for local tests
40+
[[Server]]
41+
Pattern = "POST /api/2.0/sql/statements/"
42+
Response.Body = '{"status": {"state": "SUCCEEDED"}, "manifest": {"schema": {"columns": []}}}'
43+
44+
[[Server]]
45+
Pattern = "DELETE /api/2.1/unity-catalog/tables/{name}"
46+
Response.Body = '{"status": "OK"}'

bundle/direct/dresources/resources.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ resources:
109109

110110
# database_instances: no special config
111111

112-
# database_catalogs: no special config
112+
database_catalogs:
113+
ignore_remote_changes:
114+
# Backend does not set this:
115+
- create_database_if_not_exists
113116

114-
# synced_database_tables: no special config
117+
synced_database_tables:
118+
ignore_remote_changes:
119+
# Backend does not set these fields in response (it sets effective_ counterparts instead)
120+
- database_instance_name
121+
- logical_database_name

0 commit comments

Comments
 (0)