Improve logging and waiting in mysql-replication-init

The entrypoint script of the mysql-replication-init container used quite
long sleep periods while waiting for the dump-file to arrive, which
could increase execution time considerably for small dumps (mostly
during tests).

This change reduces the sleep duration and adjusts logging accordingly
to not overly spam the logs.

Change-Id: I08f41ea15dda09a5fd274d49823ee86c4c4aa04e
diff --git a/container-images/mysql-replication-init/tools/start b/container-images/mysql-replication-init/tools/start
index 020a992..7cbcded 100755
--- a/container-images/mysql-replication-init/tools/start
+++ b/container-images/mysql-replication-init/tools/start
@@ -13,28 +13,22 @@
     echo ${timePassed}
 }
 
-while test -z ${FINISHED}; do
-    sleep 5
-    if [ -f ${FILEPATH} ]; then
-        FINISHED="true"
-    fi
-    echo "Waiting for database dump file at ${FILEPATH}"
+echo "$(date): Started"
+echo "Waiting for database dump file at ${FILEPATH}"
+while ! test -f ${FILEPATH}; do
+    sleep 1
 done
+echo "$(date): File appeared"
 
-while [ true ]; do
-    lastChange=$(getTimeFromLastChange ${FILEPATH})
-    if [ "${lastChange}" -lt 5 ]; then
-        echo "waiting"
-        sleep 1
-    else
-        echo "done"
-        break
-    fi
+echo "Waiting for the copy process to finish."
+while [ "$(getTimeFromLastChange ${FILEPATH})" -lt 5 ]; do
+    sleep 1
 done
+echo "$(date): Database dump received"
 
 # Load database dump into database
 mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD} < ${FILEPATH}
 
 # Configure and start database slave
 mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD} \
-    -e "set @replpwd='${REPL_PASSWORD}'; source /var/sql/initialize-slave.sql;"
\ No newline at end of file
+    -e "set @replpwd='${REPL_PASSWORD}'; source /var/sql/initialize-slave.sql;"
diff --git a/tests/container-images/mysql-replication-init/test_container_integration_mysql_replication_init.py b/tests/container-images/mysql-replication-init/test_container_integration_mysql_replication_init.py
index 7755ba7..c2c0f08 100644
--- a/tests/container-images/mysql-replication-init/test_container_integration_mysql_replication_init.py
+++ b/tests/container-images/mysql-replication-init/test_container_integration_mysql_replication_init.py
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import os.path
+import re
 import time
 
 import pytest
@@ -108,10 +109,8 @@
     init_container.exec_run(cmd)
     timeout = time.time() + 20
     while time.time() < timeout:
-      logs = [
-        line.strip() for line in init_container.logs().decode("utf-8").splitlines()
-      ]
-      if "done" in logs:
+      logs = init_container.logs().decode("utf-8")
+      if re.search(r"Database dump received", logs):
         break
     assert timeout > time.time()