Skip to content

Commit 4248e60

Browse files
committed
Improve robustness in scripts
- Standardize PostgreSQL commands with `-h localhost` for clarity. - Improve robustness in scripts: add checks for file writability and existence. - Adjust Gradle logging for better visibility and lifecycle tracking. - Minor enhancements to integration and helper scripts for better error handling and output tracing.
1 parent 988253a commit 4248e60

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import org.apache.tools.ant.filters.ReplaceTokens
22

3-
import java.nio.file.Files
4-
import java.nio.file.Path
5-
63
buildscript {
74
apply(from: "dependencies.gradle")
85

@@ -115,7 +112,7 @@ subprojects {
115112
]
116113

117114
testLogging {
118-
events("failed")
115+
events("started", "passed", "skipped", "failed")
119116
exceptionFormat = "full"
120117
// Uncomment the following line to see all standard output from tests (there's a ton of it!)
121118
//showStandardStreams = true
@@ -131,7 +128,7 @@ subprojects {
131128
}
132129

133130
testLogging {
134-
events("failed")
131+
events("started", "passed", "skipped", "failed")
135132
exceptionFormat = "full"
136133
// Uncomment the following line to see all standard output from tests (there's a ton of it!)
137134
//showStandardStreams = true

scripts/integration_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function main() {
1717
local test_profile="${1:-hsqldb}"
1818

1919
setup_hosts_file
20-
boot_db "${DB}" # DB is set in the Dockerfile for each image
20+
boot_db "${DB:-hsqldb}" # DB is set in the Dockerfile for each image
2121

2222
pushd "$(dirname ${script_dir})"
2323
start_ldap

scripts/lib_db_helper.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ function boot_db() {
120120
boot_log_location="/var/log/postgres-boot.log"
121121
launch_db="(POSTGRES_HOST_AUTH_METHOD=trust docker-entrypoint.sh postgres -c 'max_connections=250' &> ${boot_log_location}) &"
122122
test_connection="psql -h localhost -U postgres -c '\conninfo' &>/dev/null"
123-
init_db="psql -c 'drop database if exists uaa;' -U postgres; psql -c 'create database uaa;' -U postgres; psql -c 'drop user if exists root;' --dbname=uaa -U postgres; psql -c \"create user root with superuser password '${db_password}';\" --dbname=uaa -U postgres; psql -c 'show max_connections;' --dbname=uaa -U postgres;"
123+
init_db="psql -c 'drop database if exists uaa;' -h localhost -U postgres
124+
psql -c 'create database uaa;' -h localhost -U postgres;
125+
psql -c 'drop user if exists root;' -h localhost --dbname=uaa -U postgres;
126+
psql -c \"create user root with superuser password '${db_password}';\" -h localhost --dbname=uaa -U postgres;
127+
psql -c 'show max_connections;' -h localhost --dbname=uaa -U postgres;"
124128

125129
# Override create_db function for PostgreSQL
126130
function create_db() {
127131
local database_name="uaa_${1}"
128132
echo "Creating PostgreSQL database: ${database_name}"
129-
psql -c "create database ${database_name};" -U postgres
133+
psql -c "create database ${database_name};" -h localhost -U postgres
130134
}
131135

132136
elif [[ "${db}" = "mysql" ]]; then

scripts/lib_ldap_helper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function start_ldap() {
5757
update_ldif_paths_oracle
5858
else
5959
echo "LDAP setup could not be detected"
60-
exit 1
60+
return
6161
fi
6262
initialize_ldap
6363
}

scripts/lib_util_helper.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function is_boot_running() {
1313
start_time=$(date +%s)
1414

1515
while true; do
16-
if grep -q "$target_line" "$log_file"; then
16+
if grep "$target_line" "$log_file"; then
1717
echo "Boot Start was found in the log file."
1818
return 0
1919
fi
@@ -37,7 +37,8 @@ function is_boot_running() {
3737
##########################################
3838
function setup_hosts_file() {
3939

40-
cat <<EOF >>/etc/hosts
40+
if [[ -w "/etc/hosts" ]]; then
41+
cat <<EOF >>/etc/hosts || true
4142
127.0.0.1 testzone1.localhost
4243
127.0.0.1 testzone2.localhost
4344
127.0.0.1 testzone3.localhost
@@ -47,12 +48,15 @@ function setup_hosts_file() {
4748
127.0.0.1 testzoneinactive.localhost
4849
127.0.0.1 ldap01.example.com
4950
EOF
51+
fi
5052
}
5153

5254
########################################
5355
# Display memory of container
5456
##########################################
5557
function display_memory() {
56-
grep MemTotal /proc/meminfo || true
58+
if [[ -f "/proc/meminfo" ]]; then
59+
grep MemTotal /proc/meminfo || true
60+
fi
5761
}
5862

scripts/start_docker_database.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ main() {
3535
"
3636

3737
docker pull "${DOCKER_IMAGE}"
38+
set -x
3839
docker run \
3940
--privileged \
4041
--tty \

uaa/build.gradle

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,12 @@ integrationTest {
230230
project.logger.warn("UAA - Overriding SAML Url:"+samlUrl)
231231
}
232232

233-
testLogging {
234-
events("started", "passed", "skipped", "failed")
235-
showStandardStreams = false
236-
exceptionFormat = "full"
237-
}
238-
239233
doFirst {
240234
if (System.getProperty("skipUaaAutoStart", "false").toBoolean()) {
241235
logger.lifecycle("Skipping UAA auto-start (skipUaaAutoStart=true)")
242236
return
243237
}
244-
238+
logger.lifecycle("Killing UAA before auto-start")
245239
rootProject.tasks.named('killUaa').get().exec()
246240

247241
def bootPidFile = rootProject.file('build/boot.pid')
@@ -278,7 +272,8 @@ integrationTest {
278272
}
279273
Thread.sleep(1000)
280274
}
281-
275+
276+
logger.lifecycle("Killing UAA after auto-start")
282277
rootProject.tasks.named('killUaa').get().exec()
283278
throw new GradleException("UAA failed to start within ${maxWaitSeconds} seconds. Check ${bootLogFile.absolutePath}")
284279
}
@@ -290,6 +285,7 @@ integrationTest {
290285
}
291286

292287
logger.lifecycle("Stopping UAA application...")
288+
logger.lifecycle("Killing UAA after tests")
293289
rootProject.tasks.named('killUaa').get().exec()
294290
rootProject.file('build/boot.pid').delete()
295291
}

0 commit comments

Comments
 (0)