AutomationsAzureLoad TestingPowershellTesting

Visual Studio Online & Azure Load Testing – 502 error on site load

In a recent post I spoke about how I started using Azure Continuous Delivery on a personal project to deploy changes to my Azure instance on commit to my GitHub repository.  When changing over to this mechanism Azure gave me the option of load testing before production deployment.

Azure created everything needed and created a new web app for me as a staging environment.

The pipeline worked fine but when the load tests started firing they were not completing and 100% of the transactions failed with 502.

Failed load test results

I checked all my settings and realized Azure created everything required for the web app but didn’t create a database for the website.  Obviously, it does not copy the connection strings for the website as the database is a production instance, neither does it create a new database.

How to get the staging environment working

I want a database that automatically copies over from the production instance to a staging.  Azure has a feature called Sync Groups to will keep multiple databases in sync.  I tried using this however after speaking to a really friendly guy from Azure developer support named Yochanan.  It was determined for what I need this isn’t the right process.  Yochanan came up with the idea of using an Automation account to run a Powershell script to copy the production DB to the staging DB.

Azure Automations

Setting up the automation was really simple to do and the following blog post showed me how to use automations:

The Powershell

The Powershell script template used is here, I just updated the connection info:

$connectionName = “AzureRunAsConnection”
# Get the connection “AzureRunAsConnection ”
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName

“Logging in to Azure…”
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
catch {
if (!$servicePrincipalConnection)
$ErrorMessage = “Connection $connectionName not found.”
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception

“Removing old copy…”
Remove-AzureRmSqlDatabase -ResourceGroupName “AutomationForCase” -ServerName “yocrsrvforcase” -DatabaseName “ProdDB_Copy” -Force

“Start Copy… Please wait … ”
New-AzureRmSqlDatabaseCopy -ResourceGroupName “AutomationForCase” `
-ServerName “yocrsrvforcase” `
-DatabaseName “ProdDB” `
-CopyResourceGroupName “AutomationForCase” `
-CopyServerName “yocrsrvforcase” `
-CopyDatabaseName “ProdDB_Copy”

” !Done! ”

The automation is scheduled to run every 24 hours and the process works well.  It took about 2 minutes to delete the old database and then copy the new one.

Next Step – Run the load test again

After triggering a new build the deployment worked successfully and the load testing worked perfectly now the website has its database.

Passing load test results

Here are the load charts

Load test chart

The confidence in the website and the cloud infrastructure is even higher now after getting this working.

The outcomes

  • Load testing on the website that simulates 25 user per second load
  • A backup of the production instance every 24 hours
  • Had a try at Azure Automations

This is a great learning experience and Azure has made it so easy to complete this task.  Currently I am looking into Selenium test automation on visual studio online and will be writing a blog about that next.

Happy load testing!

Leave a Reply

Your email address will not be published. Required fields are marked *