Skip to content

Commit

Permalink
tests: ensure mysql is on the same timezone as the host machine when …
Browse files Browse the repository at this point in the history
…TZ is set
  • Loading branch information
Kehrlann committed Dec 16, 2024
1 parent cec1694 commit c48dfe9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ services:
- 3306:3306
volumes:
- ./mysql:/docker-entrypoint-initdb.d/
- /etc/localtime:/localtime-from-host
environment:
- MYSQL_ROOT_PASSWORD=changeme
- TZ=${TZ}
command:
- --sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,PAD_CHAR_TO_FULL_LENGTH
openldap:
Expand Down
23 changes: 22 additions & 1 deletion scripts/mysql/init-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -euo pipefail


# Number of gradle workers times 4, which was somewhat arbitrary but is sufficient in practice.
# We make extra dbs because a gradle worker ID can exceed the max number of workers.
NUM_OF_DATABASES_TO_CREATE=24
Expand All @@ -24,8 +25,28 @@ function createDB() {
EOSQL
}

function setTimezone() {
# If the "TZ" container is set in the container definition, then set the
# DB at the given timezone
#
# This is important because the database should run in the same timezone as the UAA,
# and, in the case of tests, the same timezone as the JVM running the tests.
#
# We achieve consistency by changing the timezone inside the DB; because setting
# it in the container is complicated. The container is missing the `timedatectl`
# binary ; and the script runs as the mysql user which does not have sudo privileges.
if [[ -n "$TZ" ]]; then
echo "Setting DB timezone to: $TZ"
mysql -uroot -pchangeme <<-EOSQL
SET GLOBAL time_zone = "$TZ";
EOSQL
fi
}



initDB

for db_id in `seq 1 $NUM_OF_DATABASES_TO_CREATE`; do
createDB $db_id
done
done

0 comments on commit c48dfe9

Please sign in to comment.