Skip to content

Commit 340eb7d

Browse files
committed
enable tests for the physical basebackup case
1 parent 6cf348d commit 340eb7d

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

.gitlab-ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ build-image-swagger-latest:
328328
script:
329329
- bash test/1.synthetic.sh
330330
- bash test/2.logical_generic.sh
331+
- bash test/4.physical_basebackup.sh
331332
after_script:
332333
- bash test/_cleanup.sh
333334
tags:

test/4.physical_basebackup.sh

+44-19
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,69 @@ 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
89
export SOURCE_HOST="${SOURCE_HOST:-172.17.0.1}"
910
export SOURCE_PORT="${SOURCE_PORT:-7432}"
1011
export SOURCE_USERNAME="${SOURCE_USERNAME:-postgres}"
1112
export SOURCE_PASSWORD="${SOURCE_PASSWORD:-secretpassword}"
1213
export POSTGRES_VERSION="${POSTGRES_VERSION:-13}"
14+
export DLE_TEST_MOUNT_DIR="/var/lib/test/dblab"
15+
export DLE_TEST_POOL_NAME="test_dblab_pool"
16+
export DLE_SERVER_PORT=${DLE_SERVER_PORT:-12345}
17+
export DLE_PORT_POOL_FROM=${DLE_PORT_POOL_FROM:-9000}
18+
export DLE_PORT_POOL_TO=${DLE_PORT_POOL_TO:-9100}
1319

1420
DIR=${0%/*}
1521

1622
if [[ "${SOURCE_HOST}" = "172.17.0.1" ]]; then
1723
### Step 0. Create source database
18-
sudo rm -rf "$(pwd)"/postgresql/"${POSTGRES_VERSION}"/test || true
24+
TMP_DATA_DIR="/tmp/dle_test/physical_basebackup"
25+
cleanup_testdata_dir() {
26+
sudo rm -rf "${TMP_DATA_DIR}"/postgresql/"${POSTGRES_VERSION}"/test || true
27+
}
28+
29+
trap cleanup_testdata_dir EXIT
30+
31+
cleanup_testdata_dir
32+
sudo docker rm postgres"${POSTGRES_VERSION}" || true
33+
1934
sudo docker run \
2035
--name postgres"${POSTGRES_VERSION}" \
2136
--label pgdb \
37+
--label dblab_test \
2238
--privileged \
2339
--publish 172.17.0.1:"${SOURCE_PORT}":5432 \
2440
--env PGDATA=/var/lib/postgresql/pgdata \
2541
--env POSTGRES_USER="${SOURCE_USERNAME}" \
2642
--env POSTGRES_PASSWORD="${SOURCE_PASSWORD}" \
2743
--env POSTGRES_DB=test \
2844
--env POSTGRES_HOST_AUTH_METHOD=md5 \
29-
--volume "$(pwd)"/postgresql/"${POSTGRES_VERSION}"/test:/var/lib/postgresql/pgdata \
45+
--volume "${TMP_DATA_DIR}"/postgresql/"${POSTGRES_VERSION}"/test:/var/lib/postgresql/pgdata \
3046
--detach \
3147
postgres:"${POSTGRES_VERSION}-alpine"
3248

3349
for i in {1..300}; do
34-
sudo docker exec -it postgres"${POSTGRES_VERSION}" psql -d test -U postgres -c 'select' > /dev/null 2>&1 && break || echo "test database is not ready yet"
50+
sudo docker exec postgres"${POSTGRES_VERSION}" psql -d test -U postgres -c 'select' > /dev/null 2>&1 && break || echo "test database is not ready yet"
3551
sleep 1
3652
done
3753

3854
# add "host replication" to pg_hba.conf
39-
sudo docker exec -it postgres"${POSTGRES_VERSION}" bash -c 'echo "host replication all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf'
55+
sudo docker exec postgres"${POSTGRES_VERSION}" bash -c 'echo "host replication all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf'
4056
# reload conf
41-
sudo docker exec -it postgres"${POSTGRES_VERSION}" psql -U postgres -c 'select pg_reload_conf()'
57+
sudo docker exec postgres"${POSTGRES_VERSION}" psql -U postgres -c 'select pg_reload_conf()'
4258

4359
# Generate data in the test database using pgbench
4460
# 1,000,000 accounts, ~0.14 GiB of data.
45-
sudo docker exec -it postgres"${POSTGRES_VERSION}" pgbench -U postgres -i -s 10 test
61+
sudo docker exec postgres"${POSTGRES_VERSION}" pgbench -U postgres -i -s 10 test
4662

4763
# Database info
48-
sudo docker exec -it postgres"${POSTGRES_VERSION}" psql -U postgres -c "\l+ test"
64+
sudo docker exec postgres"${POSTGRES_VERSION}" psql -U postgres -c "\l+ test"
4965
fi
5066

5167
### Step 1. Prepare a machine with disk, Docker, and ZFS
52-
source "${DIR}/_prerequisites.ubuntu.sh"
68+
#source "${DIR}/_prerequisites.ubuntu.sh"
5369
source "${DIR}/_zfs.file.sh"
5470

5571

@@ -69,6 +85,10 @@ yq eval -i '
6985
.global.debug = true |
7086
.global.telemetry.enabled = false |
7187
.localUI.enabled = false |
88+
.server.port = env(DLE_SERVER_PORT) |
89+
.poolManager.mountDir = env(DLE_TEST_MOUNT_DIR) |
90+
.provision.portPool.from = env(DLE_PORT_POOL_FROM) |
91+
.provision.portPool.to = env(DLE_PORT_POOL_TO) |
7292
.databaseContainer.dockerImage = "postgresai/extended-postgres:" + strenv(POSTGRES_VERSION) |
7393
.retrieval.spec.physicalRestore.options.envs.PGUSER = strenv(SOURCE_USERNAME) |
7494
.retrieval.spec.physicalRestore.options.envs.PGPASSWORD = strenv(SOURCE_PASSWORD) |
@@ -77,17 +97,19 @@ yq eval -i '
7797
.retrieval.spec.physicalSnapshot.options.envs.PGUSER = strenv(SOURCE_USERNAME) |
7898
.retrieval.spec.physicalSnapshot.options.envs.PGPASSWORD = strenv(SOURCE_PASSWORD) |
7999
.retrieval.spec.physicalSnapshot.options.envs.PGHOST = strenv(SOURCE_HOST) |
80-
.retrieval.spec.physicalSnapshot.options.envs.PGPORT = env(SOURCE_PORT)
100+
.retrieval.spec.physicalSnapshot.options.envs.PGPORT = env(SOURCE_PORT) |
101+
.retrieval.spec.physicalRestore.options.customTool.command = "pg_basebackup -X stream -D " + strenv(DLE_TEST_MOUNT_DIR) + "/" + strenv(DLE_TEST_POOL_NAME) + "/data"
81102
' "${configDir}/server.yml"
82103

83104
## Launch Database Lab server
84105
sudo docker run \
85-
--name dblab_server \
106+
--name ${DLE_SERVER_NAME} \
86107
--label dblab_control \
108+
--label dblab_test \
87109
--privileged \
88-
--publish 2345:2345 \
110+
--publish ${DLE_SERVER_PORT}:${DLE_SERVER_PORT} \
89111
--volume /var/run/docker.sock:/var/run/docker.sock \
90-
--volume /var/lib/dblab:/var/lib/dblab/:rshared \
112+
--volume ${DLE_TEST_MOUNT_DIR}:${DLE_TEST_MOUNT_DIR}/:rshared \
91113
--volume "${configDir}":/home/dblab/configs:ro \
92114
--volume "${metaDir}":/home/dblab/meta \
93115
--volume /sys/kernel/debug:/sys/kernel/debug:rw \
@@ -98,11 +120,11 @@ sudo docker run \
98120
"${IMAGE2TEST}"
99121

100122
# Check the Database Lab Engine logs
101-
sudo docker logs dblab_server -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
123+
sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
102124

103125
### Waiting for the Database Lab Engine initialization.
104126
for i in {1..30}; do
105-
curl http://localhost:2345 > /dev/null 2>&1 && break || echo "dblab is not ready yet"
127+
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
106128
sleep 10
107129
done
108130

@@ -118,7 +140,7 @@ dblab --version
118140
# Initialize CLI configuration
119141
dblab init \
120142
--environment-id=test \
121-
--url=http://localhost:2345 \
143+
--url=http://localhost:${DLE_SERVER_PORT} \
122144
--token=secret_token \
123145
--insecure
124146

@@ -134,14 +156,14 @@ dblab clone create \
134156

135157
# Connect to a clone and check the available table
136158
PGPASSWORD=secret_password psql \
137-
"host=localhost port=6000 user=dblab_user_1 dbname=test" -c '\dt+'
159+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c '\dt+'
138160

139161
# Drop table
140162
PGPASSWORD=secret_password psql \
141-
"host=localhost port=6000 user=dblab_user_1 dbname=test" -c 'drop table pgbench_accounts'
163+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c 'drop table pgbench_accounts'
142164

143165
PGPASSWORD=secret_password psql \
144-
"host=localhost port=6000 user=dblab_user_1 dbname=test" -c '\dt+'
166+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c '\dt+'
145167

146168
## Reset clone
147169
dblab clone reset testclone
@@ -151,11 +173,14 @@ dblab clone status testclone
151173

152174
# Check the database objects (everything should be the same as when we started)
153175
PGPASSWORD=secret_password psql \
154-
"host=localhost port=6000 user=dblab_user_1 dbname=test" -c '\dt+'
176+
"host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c '\dt+'
155177

156178
### Step 4. Destroy clone
157179
dblab clone destroy testclone
158180
dblab clone list
159181

182+
## Stop DLE.
183+
sudo docker stop ${DLE_SERVER_NAME}
184+
160185
### Finish. clean up
161186
source "${DIR}/_cleanup.sh"

0 commit comments

Comments
 (0)