diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 96bc9ec1..6b06f669 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,7 +1,5 @@ trigger: - - master - dev - - 1ES pr: branches: @@ -16,9 +14,6 @@ schedules: - dev always: true -variables: -- group: DjangoTestApp - jobs: - job: Windows pool: @@ -149,7 +144,7 @@ jobs: displayName: Restart SQL Server - powershell: | - (Get-Content -ReadCount 0 testapp\settings.py) -replace 'MyPassword42', '$(TestAppPassWord)' | Set-Content testapp\settings.py + (Get-Content -ReadCount 0 testapp\settings.py) -replace 'MyPassword42', '$(TestAppPassword)' | Set-Content testapp\settings.py displayName: Change PASSWORD in settings.py - powershell: | @@ -266,6 +261,33 @@ jobs: docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=$(TestAppPassword)' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list + + # Wait for SQL Server to be ready with increased timeout + echo "Waiting for SQL Server to start..." + + # Extended wait for the container to be running and SQL Server service to be listening + for i in {1..60}; do + if docker logs $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest) 2>&1 | grep -q "SQL Server is now ready for client connections"; then + echo "SQL Server service is ready after $i attempts ($(($i * 3)) seconds)" + break + fi + echo "Attempt $i: Waiting for SQL Server service to be ready, checking again in 3 seconds..." + sleep 3 + done + + # Increased wait to ensure full initialization for database operations + echo "Waiting additional 60 seconds for full SQL Server initialization..." + sleep 60 + + # Verify we can connect using a simple network test first + echo "Testing SQL Server connectivity..." + if ! timeout 30 bash -c 'until echo > /dev/tcp/localhost/1433; do sleep 1; done'; then + echo "Cannot connect to SQL Server on port 1433" + docker logs $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest) + exit 1 + fi + + echo "SQL Server is ready and accepting connections" displayName: Install SQL Server - script: | @@ -303,6 +325,41 @@ jobs: fi displayName: Install ODBC Driver + - script: | + # Install mssql-tools to get sqlcmd + sudo ACCEPT_EULA=Y apt-get install -y mssql-tools + + # Wait for SQL Server authentication to be ready (retry loop) + echo "Waiting for SQL Server authentication to be ready..." + export PATH="$PATH:/opt/mssql-tools/bin" + + # Retry authentication until SQL Server finishes its internal upgrade process + for i in {1..30}; do + echo "Authentication attempt $i of 30..." + # Force IPv4 TCP to avoid potential localhost/IPv6 resolution issues on agents + if sqlcmd -S "tcp:127.0.0.1,1433" -U sa -P "$(TestAppPassword)" -Q "SELECT 1 AS test" -l 10 >/dev/null 2>&1; then + echo "✅ SQL Server authentication successful after $i attempts!" + break + else + if [ $i -eq 30 ]; then + echo "❌ SQL Server authentication FAILED after 30 attempts!" + echo "Final attempt with verbose output:" + sqlcmd -S "tcp:127.0.0.1,1433" -U sa -P "$(TestAppPassword)" -Q "SELECT 1 AS test" -l 10 + echo "" + echo "Container logs:" + docker logs $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest) + exit 1 + else + echo "Authentication failed (attempt $i), waiting 10 seconds before retry..." + echo "This is normal - SQL Server may still be upgrading internal databases..." + sleep 10 + fi + fi + done + + echo "SQL Server is fully ready for authentication!" + displayName: Wait for SQL Server Authentication + - script: | # Since pylibmc isn't supported for Python 3.12+ # We need to install libmemcached-dev to build it - dependency for Django test suite @@ -323,6 +380,13 @@ jobs: sed -i 's/MyPassword42/$(TestAppPassword)/g' testapp/settings.py displayName: Change PASSWORD in settings.py + - script: | + # Force Django DB host to IPv4 loopback to avoid IPv6 localhost resolution issues + sed -i "s|\"HOST\": \"localhost\"|\"HOST\": \"127.0.0.1\"|g" testapp/settings.py + echo "Updated DB HOST to 127.0.0.1" + grep -n "\"HOST\"" -n testapp/settings.py + displayName: Use IPv4 loopback for DB host + - script: tox -e $(tox.env) displayName: Run tox