From a6cb885cfe53519615c8ee5fc15a39abe06d0696 Mon Sep 17 00:00:00 2001 From: Yunxe <72926033+Yunxe@users.noreply.github.com> Date: Sun, 22 Oct 2023 21:02:22 +0800 Subject: [PATCH] Fix Telemetry Service SQL Server pipeline flaky test (#734) * change tag to 2022-RTM-GDR1-ubuntu-20.04 * modified users * add docker health check * use docker health check for mysql --- azure-pipelines/azure-pipelines.yml | 7 ++++-- .../telemetryservice/mysql/checkoutput.sh | 17 ++++--------- .../telemetryservice/sqlserver/checkoutput.sh | 24 ++++++------------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 79dce289f..af30f214c 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -384,13 +384,16 @@ stages: displayName: docker run tdengine and checkoutput - script: | set -e - docker run -itd --network host --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:8.1.0 + docker run -itd --network host --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + --health-cmd='mysqladmin ping -h localhost -uroot' --health-interval=5s --health-timeout=5s --health-retries=20 \ + mysql:8.1.0 bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/mysql/checkoutput.sh displayName: docker run mysql and checkoutput - script: | set -e docker run -itd --network host --name sqlserver -e ACCEPT_EULA=Y -e SA_PASSWORD=Some_Strong_Password \ - mcr.microsoft.com/mssql/server:2022-CU7-ubuntu-20.04 + --health-cmd="/opt/mssql-tools/bin/sqlcmd -U sa -P Some_Strong_Password -Q 'select name from sys.databases'" --health-interval=5s --health-timeout=5s --health-retries=20 \ + mcr.microsoft.com/mssql/server:2022-CU7-ubuntu-20.04 bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/sqlserver/checkoutput.sh displayName: docker run sqlserver and checkoutput diff --git a/examples/telemetryservice/mysql/checkoutput.sh b/examples/telemetryservice/mysql/checkoutput.sh index 00044cf25..15878b2f6 100644 --- a/examples/telemetryservice/mysql/checkoutput.sh +++ b/examples/telemetryservice/mysql/checkoutput.sh @@ -1,19 +1,10 @@ #!/bin/bash MySQLOutput=2 -sleep 3 -for i in {1..50} -do - output=$(docker exec mysql mysql -u root -e "Show databases;" 2>&1 | grep 'ERROR' | wc -l) - #echo $output - if [[ $output -eq 0 ]] - then - echo $output - break - elif [[ $i -eq 50 ]] - then - exit 1 - fi +echo "Waiting for MySQL to be ready..." +while [[ "$(docker inspect --format='{{.State.Health.Status}}' mysql)" != "healthy" ]]; do + sleep 5 done +echo "MySQL is ready." # init MySQL Table docker exec mysql mysql -u root \ diff --git a/examples/telemetryservice/sqlserver/checkoutput.sh b/examples/telemetryservice/sqlserver/checkoutput.sh index 33fa39068..48ea9386f 100644 --- a/examples/telemetryservice/sqlserver/checkoutput.sh +++ b/examples/telemetryservice/sqlserver/checkoutput.sh @@ -1,29 +1,19 @@ #!bin/bash SQLServerOutput=2 -sleep 6 -for i in {1..50} -do - output=$(docker exec sqlserver /opt/mssql-tools/bin/sqlcmd \ - -S localhost -U sa -P Some_Strong_Password \ - -Q "select name from sys.databases" | grep 'Error' | wc -l) - echo $output - if [[ $output -eq 0 ]] - then - break - elif [[ $i -eq 50 ]] - then - exit 1 - fi +echo "Waiting for SQL Server to be ready..." +while [[ "$(docker inspect --format='{{.State.Health.Status}}' sqlserver)" != "healthy" ]]; do + sleep 5 done +echo "SQL Server is ready." # init SQLServer Table -docker exec sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Some_Strong_Password \ +docker exec sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Some_Strong_Password \ -Q "Create database shifu;" -docker exec sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Some_Strong_Password \ +docker exec sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Some_Strong_Password \ -d shifu -Q "CREATE TABLE testTable ( TelemetryID INT IDENTITY(1,1) PRIMARY KEY, DeviceName VARCHAR(255), TelemetryData TEXT, TelemetryTimeStamp DATETIME );" -docker exec sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Some_Strong_Password \ +docker exec sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Some_Strong_Password \ -d shifu -Q "Select * from shifu.dbo.testTable;" for i in {1..30}