Skip to content

Commit 7871c44

Browse files
committed
fix tests for the RDS case
1 parent 340eb7d commit 7871c44

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

test/5.logical_rds.sh

+28-12
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ set -euxo pipefail
33

44
TAG="${TAG:-"master"}"
55
IMAGE2TEST="registry.gitlab.com/postgres-ai/database-lab/dblab-server:${TAG}"
6+
DLE_SERVER_NAME="dblab_server_test"
67

78
# Environment variables for replacement rules
9+
export DLE_TEST_MOUNT_DIR="/var/lib/test/dblab"
10+
export DLE_TEST_POOL_NAME="test_dblab_pool"
11+
export DLE_SERVER_PORT=${DLE_SERVER_PORT:-12345}
12+
export DLE_PORT_POOL_FROM=${DLE_PORT_POOL_FROM:-9000}
13+
export DLE_PORT_POOL_TO=${DLE_PORT_POOL_TO:-9100}
814
export POSTGRES_VERSION="${POSTGRES_VERSION:-13}"
915
export SOURCE_DBNAME="${SOURCE_DBNAME:-"test"}"
1016
export SOURCE_USERNAME="${SOURCE_USERNAME:-"test_user"}"
@@ -38,11 +44,17 @@ yq eval -i '
3844
.global.debug = true |
3945
.global.telemetry.enabled = false |
4046
.localUI.enabled = false |
47+
.server.port = env(DLE_SERVER_PORT) |
48+
.poolManager.mountDir = env(DLE_TEST_MOUNT_DIR) |
49+
.provision.portPool.from = env(DLE_PORT_POOL_FROM) |
50+
.provision.portPool.to = env(DLE_PORT_POOL_TO) |
4151
.databaseContainer.dockerImage = "postgresai/extended-postgres:" + strenv(POSTGRES_VERSION) |
52+
.retrieval.spec.logicalDump.options.dumpLocation = env(DLE_TEST_MOUNT_DIR) + "/" + env(DLE_TEST_POOL_NAME) + "/dump" |
4253
.retrieval.spec.logicalDump.options.source.connection.dbname = strenv(SOURCE_DBNAME) |
4354
.retrieval.spec.logicalDump.options.source.connection.username = strenv(SOURCE_USERNAME) |
4455
.retrieval.spec.logicalDump.options.source.rdsIam.awsRegion = strenv(AWS_REGION) |
45-
.retrieval.spec.logicalDump.options.source.rdsIam.dbInstanceIdentifier = strenv(RDS_DB_IDENTIFIER)
56+
.retrieval.spec.logicalDump.options.source.rdsIam.dbInstanceIdentifier = strenv(RDS_DB_IDENTIFIER) |
57+
.retrieval.spec.logicalRestore.options.dumpLocation = env(DLE_TEST_MOUNT_DIR) + "/" + env(DLE_TEST_POOL_NAME) + "/dump"
4658
' "${configDir}/server.yml"
4759

4860
# Download AWS RDS certificate
@@ -51,15 +63,16 @@ curl https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem \
5163

5264
## Run Database Lab Engine
5365
sudo docker run \
54-
--name dblab_server \
66+
--name ${DLE_SERVER_NAME} \
5567
--label dblab_control \
68+
--label dblab_test \
5669
--privileged \
57-
--publish 2345:2345 \
70+
--publish ${DLE_SERVER_PORT}:${DLE_SERVER_PORT} \
5871
--volume "${configDir}":/home/dblab/configs:ro \
5972
--volume "${metaDir}":/home/dblab/meta \
60-
--volume /var/lib/dblab/dblab_pool/dump:/var/lib/dblab/dblab_pool/dump \
73+
--volume ${DLE_TEST_MOUNT_DIR}/${DLE_TEST_POOL_NAME}/dump:${DLE_TEST_MOUNT_DIR}/${DLE_TEST_POOL_NAME}/dump \
74+
--volume ${DLE_TEST_MOUNT_DIR}:${DLE_TEST_MOUNT_DIR}/:rshared \
6175
--volume /var/run/docker.sock:/var/run/docker.sock \
62-
--volume /var/lib/dblab:/var/lib/dblab/:rshared \
6376
--volume /sys/kernel/debug:/sys/kernel/debug:rw \
6477
--volume /lib/modules:/lib/modules:ro \
6578
--volume /proc:/host_proc:ro \
@@ -71,11 +84,11 @@ sudo docker run \
7184
"${IMAGE2TEST}"
7285

7386
# Check the Database Lab Engine logs
74-
sudo docker logs dblab_server -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
87+
sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
7588

7689
### Waiting for the Database Lab Engine initialization.
7790
for i in {1..30}; do
78-
curl http://localhost:2345 > /dev/null 2>&1 && break || echo "dblab is not ready yet"
91+
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
7992
sleep 10
8093
done
8194

@@ -91,7 +104,7 @@ dblab --version
91104
# Initialize CLI configuration
92105
dblab init \
93106
--environment-id=test \
94-
--url=http://localhost:2345 \
107+
--url=http://localhost:${DLE_SERVER_PORT} \
95108
--token=secret_token \
96109
--insecure
97110

@@ -107,14 +120,14 @@ dblab clone create \
107120

108121
# Connect to a clone and check the available table
109122
PGPASSWORD=secret_password psql \
110-
"host=localhost port=6000 user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c '\dt+'
123+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c '\dt+'
111124

112125
# Drop table
113126
PGPASSWORD=secret_password psql \
114-
"host=localhost port=6000 user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c 'drop table pgbench_accounts'
127+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c 'drop table pgbench_accounts'
115128

116129
PGPASSWORD=secret_password psql \
117-
"host=localhost port=6000 user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c '\dt+'
130+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c '\dt+'
118131

119132
## Reset clone
120133
dblab clone reset testclone
@@ -124,11 +137,14 @@ dblab clone status testclone
124137

125138
# Check the database objects (everything should be the same as when we started)
126139
PGPASSWORD=secret_password psql \
127-
"host=localhost port=6000 user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c '\dt+'
140+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=${SOURCE_DBNAME}" -c '\dt+'
128141

129142
### Step 4. Destroy clone
130143
dblab clone destroy testclone
131144
dblab clone list
132145

146+
## Stop DLE.
147+
sudo docker stop ${DLE_SERVER_NAME}
148+
133149
### Finish. clean up
134150
source "${DIR}/_cleanup.sh"

0 commit comments

Comments
 (0)