mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
5 hours ago ede1b306bc6f3ff2332e0cf31f6f5be1082b1217
Stop Cassandra and Postgres after LDAP CI tests (#1332)

## Summary

- Stop Cassandra and PostgreSQL when their LDAP test steps exit,
including when a test fails.
- Free their resources before the Linux replication test. Docker removes
both containers after they stop because they run with `--rm`.
- Stop each container by ID. If Docker confirms that the container is no
longer running, preserve the LDAP step's exit status. If cleanup fails
and the container is still running or its state is unknown, log the
error and fail an otherwise successful step. A failed LDAP step keeps
its original exit code.

## Verification

- All 20 Bash scenarios passed with stubbed Docker and OpenDJ commands.
They cover both databases, failed starts, readiness timeouts, LDAP
failures, automatic removal, and cleanup failures.
- `actionlint`, ShellCheck on the cleanup script, and `git diff --check`
passed. Running ShellCheck across the workflow produced the same
diagnostics as before the change.
- The local Docker daemon was unavailable for a run with real
containers.
1 files modified
1 files added
40 ■■■■■ changed files
.github/scripts/stop-test-container.sh 34 ●●●●● patch | view | raw | blame | history
.github/workflows/build.yml 6 ●●●●● patch | view | raw | blame | history
.github/scripts/stop-test-container.sh
New file
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# The contents of this file are subject to the terms of the Common Development and
# Distribution License (the License). You may not use this file except in compliance with the
# License.
#
# You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
# specific language governing permission and limitations under the License.
#
# When distributing Covered Software, include this CDDL Header Notice in each file and include
# the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
# Header, with the fields enclosed by brackets [] replaced by your own identifying
# information: "Portions copyright [year] [name of copyright owner]".
#
# Copyright 2026 3A Systems, LLC.
step_status=$1
container_id=$2
if stop_output=$(docker stop "$container_id" 2>&1); then
  exit "$step_status"
else
  stop_status=$?
fi
# Docker may have already removed a container started with --rm.
if running=$(docker ps --quiet --filter "id=$container_id") && [[ -z "$running" ]]; then
  exit "$step_status"
fi
printf '%s\n' "$stop_output" >&2
if (( step_status == 0 )); then
  exit "$stop_status"
fi
exit "$step_status"
.github/workflows/build.yml
@@ -289,7 +289,8 @@
    - name: Test LDAP in Cassandra
      if: runner.os == 'Linux'
      run:   |
        docker run --rm -it -d -p 9042:9042 --name cassandra cassandra
        container_id=$(docker run --rm -it -d -p 9042:9042 --name cassandra cassandra)
        trap 'bash .github/scripts/stop-test-container.sh "$?" "$container_id" || exit "$?"' EXIT
        timeout 5m bash -c 'until docker logs cassandra | grep -q "Created default superuser role"; do sleep 5; done'
        export OPENDJ_JAVA_ARGS="-server -Xmx512m -Ddatastax-java-driver.basic.contact-points.0=localhost:9042 -Ddatastax-java-driver.basic.load-balancing-policy.local-datacenter=datacenter1"
        opendj-server-legacy/target/package/opendj/setup -h localhost -p 1389 --ldapsPort 1636 --adminConnectorPort 4444 --enableStartTLS --generateSelfSignedCertificate --rootUserDN "cn=Directory Manager" --rootUserPassword password --cli --acceptLicense --no-prompt
@@ -304,7 +305,8 @@
    - name: Test LDAP in Postgres
      if: runner.os == 'Linux'
      run:   |
        docker run --rm -it -d -p 5432:5432 -e POSTGRES_DB=database_name -e POSTGRES_PASSWORD=password --name postgres postgres
        container_id=$(docker run --rm -it -d -p 5432:5432 -e POSTGRES_DB=database_name -e POSTGRES_PASSWORD=password --name postgres postgres)
        trap 'bash .github/scripts/stop-test-container.sh "$?" "$container_id" || exit "$?"' EXIT
        timeout 5m bash -c 'until docker logs postgres | grep -q "database system is ready to accept connections"; do sleep 5; done'
        export OPENDJ_JAVA_ARGS="-server -Xmx512m"
        opendj-server-legacy/target/package/opendj/setup -h localhost -p 1389 --ldapsPort 1636 --adminConnectorPort 4444 --enableStartTLS --generateSelfSignedCertificate --rootUserDN "cn=Directory Manager" --rootUserPassword password --cli --acceptLicense --no-prompt