Skip to content

Commit 6dc02cc

Browse files
committed
feat: check the state of containers after waiting loops and fail immediately, if there is still no success (#309)
1 parent 5211d5c commit 6dc02cc

File tree

5 files changed

+71
-12
lines changed

5 files changed

+71
-12
lines changed

test/1.synthetic.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,28 @@ sudo docker run \
3535
--detach \
3636
postgres:"${POSTGRES_VERSION}"-alpine
3737

38+
check_database_readiness(){
39+
sudo docker exec dblab_pg_initdb psql -U postgres -c 'select' > /dev/null 2>&1
40+
return $?
41+
}
42+
3843
for i in {1..300}; do
39-
sudo docker exec dblab_pg_initdb psql -U postgres -c 'select' > /dev/null 2>&1 && break || echo "test database is not ready yet"
44+
check_database_readiness && break || echo "test database is not ready yet"
4045
sleep 1
4146
done
4247

48+
check_database_readiness || (echo "test database is not ready" && exit 1)
49+
4350
# Restart container explicitly after initdb to make sure that the server will not receive a shutdown request and queries will not be interrupted.
4451
sudo docker restart dblab_pg_initdb
4552

4653
for i in {1..300}; do
47-
sudo docker exec dblab_pg_initdb psql -U postgres -c 'select' > /dev/null 2>&1 && break || echo "test database is not ready yet"
54+
check_database_readiness && break || echo "test database is not ready yet"
4855
sleep 1
4956
done
5057

58+
check_database_readiness || (echo "test database is not ready" && exit 1)
59+
5160
# Create the test database
5261
sudo docker exec dblab_pg_initdb psql -U postgres -c 'create database test'
5362

@@ -109,12 +118,18 @@ sudo docker run \
109118
# Check the Database Lab Engine logs
110119
sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER ${DLE_SERVER_PORT}]: "$0}' &
111120

121+
check_dle_readiness(){
122+
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1
123+
return $?
124+
}
125+
112126
### Waiting for the Database Lab Engine initialization.
113127
for i in {1..300}; do
114-
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
128+
check_dle_readiness && break || echo "Database Lab Engine is not ready yet"
115129
sleep 1
116130
done
117131

132+
check_dle_readiness || (echo "Database Lab Engine is not ready" && exit 1)
118133

119134
### Step 3. Start cloning
120135

@@ -168,12 +183,14 @@ PGPASSWORD=secret_password psql \
168183
## Restart DLE.
169184
sudo docker restart ${DLE_SERVER_NAME}
170185

171-
### Waiting for the Database Lab Engine to start.
186+
### Waiting for the Database Lab Engine initialization.
172187
for i in {1..300}; do
173-
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
188+
check_dle_readiness && break || echo "Database Lab Engine is not ready yet"
174189
sleep 1
175190
done
176191

192+
check_dle_readiness || (echo "Database Lab Engine is not ready" && exit 1)
193+
177194
## Reset clone.
178195
dblab clone reset testclone
179196

test/2.logical_generic.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ if [[ "${SOURCE_HOST}" = "172.17.0.1" ]]; then
4747
--detach \
4848
postgres:"${POSTGRES_VERSION}-alpine"
4949

50+
check_database_readiness(){
51+
sudo docker exec postgres"${POSTGRES_VERSION}" psql -d "${SOURCE_DBNAME}" -U postgres -c 'select' > /dev/null 2>&1
52+
return $?
53+
}
54+
5055
for i in {1..300}; do
51-
sudo docker exec postgres"${POSTGRES_VERSION}" psql -d "${SOURCE_DBNAME}" -U postgres -c 'select' > /dev/null 2>&1 && break || echo "test database is not ready yet"
56+
check_database_readiness && break || echo "test database is not ready yet"
5257
sleep 1
5358
done
5459

60+
check_database_readiness || (echo "test database is not ready" && exit 1)
61+
5562
# Generate data in the test database using pgbench
5663
# 1,000,000 accounts, ~0.14 GiB of data.
5764
sudo docker exec postgres"${POSTGRES_VERSION}" pgbench -U postgres -i -s 10 "${SOURCE_DBNAME}"
@@ -122,12 +129,18 @@ sudo docker run \
122129
# Check the Database Lab Engine logs
123130
sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
124131

132+
check_dle_readiness(){
133+
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1
134+
return $?
135+
}
136+
125137
### Waiting for the Database Lab Engine initialization.
126138
for i in {1..300}; do
127-
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
139+
check_dle_readiness && break || echo "Database Lab Engine is not ready yet"
128140
sleep 1
129141
done
130142

143+
check_dle_readiness || (echo "Database Lab Engine is not ready" && exit 1)
131144

132145
### Step 3. Start cloning
133146

test/3.physical_walg.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,19 @@ trap cleanup_service_containers EXIT
114114
# Check the Database Lab Engine logs
115115
sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
116116

117+
check_dle_readiness(){
118+
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1
119+
return $?
120+
}
121+
117122
### Waiting for the Database Lab Engine initialization.
118123
for i in {1..30}; do
119-
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
124+
check_dle_readiness && break || echo "Database Lab Engine is not ready yet"
120125
sleep 10
121126
done
122127

128+
check_dle_readiness || (echo "Database Lab Engine is not ready" && exit 1)
129+
123130
# Test increasing default configuration parameters from pg_controldata. If the Database Lab Engine will start successfully, the test is passed.
124131
sudo docker exec ${DLE_SERVER_NAME} bash -c "echo -e '\nmax_connections = 300' >> ${DLE_TEST_MOUNT_DIR}/${DLE_TEST_POOL_NAME}/data/postgresql.dblab.postgresql.conf"
125132
sudo docker exec ${DLE_SERVER_NAME} bash -c "echo 'max_prepared_transactions = 5' >> ${DLE_TEST_MOUNT_DIR}/${DLE_TEST_POOL_NAME}/data/postgresql.dblab.postgresql.conf"
@@ -138,10 +145,12 @@ sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER dblab_serv
138145

139146
### Waiting for the Database Lab Engine initialization.
140147
for i in {1..30}; do
141-
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
148+
check_dle_readiness && break || echo "Database Lab Engine is not ready yet"
142149
sleep 10
143150
done
144151

152+
check_dle_readiness || (echo "Database Lab Engine is not ready" && exit 1)
153+
145154
### Step 3. Start cloning
146155

147156
# Install Database Lab client CLI

test/4.physical_basebackup.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ if [[ "${SOURCE_HOST}" = "172.17.0.1" ]]; then
4646
--detach \
4747
postgres:"${POSTGRES_VERSION}-alpine"
4848

49+
check_database_readiness(){
50+
sudo docker exec postgres"${POSTGRES_VERSION}" psql -d test -U postgres -c 'select' > /dev/null 2>&1
51+
return $?
52+
}
53+
4954
for i in {1..300}; do
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"
55+
check_database_readiness && break || echo "test database is not ready yet"
5156
sleep 1
5257
done
5358

59+
check_database_readiness || (echo "test database is not ready" && exit 1)
60+
5461
# add "host replication" to pg_hba.conf
5562
sudo docker exec postgres"${POSTGRES_VERSION}" bash -c 'echo "host replication all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf'
5663
# reload conf
@@ -144,12 +151,19 @@ trap cleanup_service_containers EXIT
144151
# Check the Database Lab Engine logs
145152
sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
146153

154+
check_dle_readiness(){
155+
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1
156+
return $?
157+
}
158+
147159
### Waiting for the Database Lab Engine initialization.
148160
for i in {1..30}; do
149-
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
161+
check_dle_readiness && break || echo "Database Lab Engine is not ready yet"
150162
sleep 10
151163
done
152164

165+
check_dle_readiness || (echo "Database Lab Engine is not ready" && exit 1)
166+
153167
### Step 3. Start cloning
154168

155169
# Install Database Lab client CLI

test/5.logical_rds.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ sudo docker run \
9191
# Check the Database Lab Engine logs
9292
sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk '{print "[CONTAINER dblab_server]: "$0}' &
9393

94+
check_dle_readiness(){
95+
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1
96+
return $?
97+
}
98+
9499
### Waiting for the Database Lab Engine initialization.
95100
for i in {1..30}; do
96-
curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo "dblab is not ready yet"
101+
check_dle_readiness && break || echo "Database Lab Engine is not ready yet"
97102
sleep 10
98103
done
99104

105+
check_dle_readiness || (echo "Database Lab Engine is not ready" && exit 1)
100106

101107
### Step 3. Start cloning
102108

0 commit comments

Comments
 (0)