Skip to content

Commit

Permalink
Rest Point leak fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vinitsuri-msft committed Oct 5, 2016
1 parent d4c9a7f commit 2700f36
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 32 deletions.
30 changes: 19 additions & 11 deletions Tasks/QuickPerfTest/Invoke-QuickPerfTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function InitializeRestHeaders()
return $restHeaders
}

function InvokeRestMethod($headers, $contentType, $uri , $method= "Get", $body)
{
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint($uri)
$result = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Method $method -Headers $headers -Body $body
$ServicePoint.CloseConnectionGroup("")
return $result
}

function ComposeTestDropJson($name, $duration, $homepage, $vu)
{
$tdjson = @"
Expand Down Expand Up @@ -66,15 +74,15 @@ $tdjson = @"
function CreateTestDrop($headers, $dropJson)
{
$uri = [String]::Format("{0}/_apis/clt/testdrops?api-version=1.0", $CltAccountUrl)
$drop = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Post -Headers $headers -Body $dropJson
$drop = InvokeRestMethod -contentType "application/json" -uri $uri -method Post -headers $headers -body $dropJson

return $drop
}

function GetTestDrop($headers, $drop)
{
$uri = [String]::Format("{0}/_apis/clt/testdrops/{1}?api-version=1.0", $CltAccountUrl, $drop.id)
$testdrop = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Headers $headers
$testdrop = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers

return $testdrop
}
Expand All @@ -91,15 +99,15 @@ function UploadTestDrop($testdrop)
function GetTestRuns($headers)
{
$uri = [String]::Format("{0}/_apis/clt/testruns?api-version=1.0", $CltAccountUrl)
$runs = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Headers $headers
$runs = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers

return $runs
}

function GetTestRunUri($testRunId, $headers)
{
$uri = [String]::Format("{0}/_apis/clt/testruns/{1}?api-version=1.0", $CltAccountUrl,$testRunId)
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Headers $headers
$run = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers

return $run.WebResultUrl
}
Expand All @@ -119,7 +127,7 @@ function MonitorTestRun($headers, $run)
do
{
Start-Sleep -s 5
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
$run = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers
if ($prevState -ne $run.state -or $prevSubState -ne $run.subState)
{
$prevState = $run.state
Expand All @@ -129,10 +137,10 @@ function MonitorTestRun($headers, $run)
}
while (RunInProgress $run)

$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
$run = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers
Write-Output "------------------------------------"
$uri = [String]::Format("{0}/_apis/clt/testruns/{1}/messages?api-version=1.0", $CltAccountUrl, $run.id)
$messages = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
$messages = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers

if ($messages)
{
Expand Down Expand Up @@ -172,7 +180,7 @@ $trjson = @"
function QueueTestRun($headers, $runJson)
{
$uri = [String]::Format("{0}/_apis/clt/testruns?api-version=1.0", $CltAccountUrl)
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Post -Headers $headers -Body $runJson
$run = InvokeRestMethod -contentType "application/json" -uri $uri -method Post -headers $headers -body $runJson

$start = @"
{
Expand All @@ -181,8 +189,8 @@ $start = @"
"@

$uri = [String]::Format("{0}/_apis/clt/testruns/{1}?api-version=1.0", $CltAccountUrl, $run.id)
Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Patch -Headers $headers -Body $start
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
InvokeRestMethod -contentType "application/json" -uri $uri -method Patch -headers $headers -body $start
$run = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers

return $run
}
Expand Down Expand Up @@ -286,5 +294,5 @@ else
}


Write-Output "Finished Quick Perf Test Script"
Write-Output "Quick Perf Test Script execution completed"

2 changes: 1 addition & 1 deletion Tasks/QuickPerfTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 9
"Patch": 11
},
"demands": [
"msbuild",
Expand Down
22 changes: 15 additions & 7 deletions Tasks/RunJMeterLoadTest/Start-ApacheJMeterTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,26 @@ function InitializeRestHeaders()
return $restHeaders
}

function InvokeRestMethod($headers, $contentType, $uri , $method= "Get", $body)
{
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint($uri)
$result = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Method $method -Headers $headers -Body $body
$ServicePoint.CloseConnectionGroup("")
return $result
}

function CreateTestDrop($headers)
{
$uri = [String]::Format("{0}/_apis/clt/testdrops?{1}", $global:ElsAccountUrl, $apiVersion)
$drop = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers -Method Post -Body "{ ""dropType"": ""TestServiceBlobDrop"" }"
$drop = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers -method Post -body "{ ""dropType"": ""TestServiceBlobDrop"" }"
return $drop
}

function Get($headers, $uri)
{
try
{
$result = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Headers $headers
$result = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers
return $result
}
catch
Expand Down Expand Up @@ -85,7 +93,7 @@ function GetTestErrors($headers, $run)
function QueueTestRun($headers, $runJson)
{
$uri = [String]::Format("{0}/_apis/clt/testruns?{1}", $global:ElsAccountUrl, $apiVersion)
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Post -Headers $headers -Body $runJson
$run = InvokeRestMethod -contentType "application/json" -uri $uri -method Post -headers $headers -body $runJson

$start = @"
{
Expand All @@ -94,8 +102,8 @@ $start = @"
"@

$uri = [String]::Format("{0}/_apis/clt/testruns/{1}?{2}", $global:ElsAccountUrl, $run.id, $apiVersion)
Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Patch -Headers $headers -Body $start
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
InvokeRestMethod -contentType "application/json" -uri $uri -method Patch -headers $headers -body $start
$run = InvokeRestMethod -contentType "application/json" -userAgent $userAgent -uri $uri -headers $headers

return $run
}
Expand Down Expand Up @@ -127,7 +135,7 @@ function PrintErrorSummary($headers, $run)
function ShowMessages($headers, $run)
{
$uri = [String]::Format("{0}/_apis/clt/testruns/{1}/messages?{2}", $global:ElsAccountUrl, $run.id, $apiVersion)
$messages = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
$messages = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers
if ($messages)
{
$sMessages = $messages.value | Sort-Object loggedDate
Expand Down Expand Up @@ -360,5 +368,5 @@ else
("Connection '{0}' failed for service '{1}'" -f $connectedServiceName, $connectedServiceDetails.Url.AbsoluteUri) >> $summaryFile
}

WriteTaskMessages "Finished JMeter Test Script"
WriteTaskMessages "JMeter Test Script execution completed"

2 changes: 1 addition & 1 deletion Tasks/RunJMeterLoadTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 5
"Patch": 7
},
"demands": [
"azureps"
Expand Down
31 changes: 20 additions & 11 deletions Tasks/RunLoadTest/Start-CloudLoadTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,26 @@ function InitializeRestHeaders()
return $restHeaders
}

function InvokeRestMethod($headers, $contentType, $uri , $method= "Get", $body)
{
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint($uri)
$result = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Method $method -Headers $headers -Body $body
$ServicePoint.CloseConnectionGroup("")
return $result
}

function CreateTestDrop($headers)
{
$uri = [String]::Format("{0}/_apis/clt/testdrops?{1}", $global:ElsAccountUrl, $apiVersion)
$drop = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers -Method Post -Body "{ ""dropType"": ""TestServiceBlobDrop"" }"
$drop = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers -method Post -body "{ ""dropType"": ""TestServiceBlobDrop"" }"
return $drop
}

function Get($headers, $uri)
{
try
{
$result = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -TimeoutSec $global:RestTimeout -Uri $uri -Headers $headers
$result = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers
return $result
}
catch
Expand Down Expand Up @@ -87,7 +95,7 @@ function GetTestErrors($headers, $run)
function QueueTestRun($headers, $runJson)
{
$uri = [String]::Format("{0}/_apis/clt/testruns?{1}", $global:ElsAccountUrl, $apiVersion)
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Post -Headers $headers -Body $runJson
$run = InvokeRestMethod -contentType "application/json" -uri $uri -method Post -headers $headers -body $runJson

$start = @"
{
Expand All @@ -96,8 +104,8 @@ $start = @"
"@

$uri = [String]::Format("{0}/_apis/clt/testruns/{1}?{2}", $global:ElsAccountUrl, $run.id, $apiVersion)
Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Patch -Headers $headers -Body $start
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
InvokeRestMethod -contentType "application/json" -uri $uri -method Patch -headers $headers -body $start
$run = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers

return $run
}
Expand All @@ -110,8 +118,8 @@ $stop = @"
}
"@
$uri = [String]::Format("{0}/_apis/clt/testruns/{1}?{2}", $global:ElsAccountUrl, $run.id, $apiVersion)
Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Method Patch -Headers $headers -Body $stop
$run = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
InvokeRestMethod -contentType "application/json" -uri $uri -method Patch -headers $headers -body $stop
$run = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers
return $run

}
Expand Down Expand Up @@ -157,7 +165,7 @@ function CheckTestErrors($headers, $run)
if ($global:MonitorThresholds)
{
$uri = [String]::Format("{0}/_apis/clt/testruns/{1}/errors?type=ThresholdMessage&detailed=True&{2}", $global:ElsAccountUrl, $run.id, $apiVersion)
$errors = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
$errors = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers

if ($errors -and $errors.count -gt 0 -and $errors.types.count -gt 0)
{
Expand All @@ -177,7 +185,7 @@ function CheckTestErrors($headers, $run)
function ShowMessages($headers, $run)
{
$uri = [String]::Format("{0}/_apis/clt/testruns/{1}/messages?{2}", $global:ElsAccountUrl, $run.id, $apiVersion)
$messages = Invoke-RestMethod -ContentType "application/json" -UserAgent $userAgent -Uri $uri -Headers $headers
$messages = InvokeRestMethod -contentType "application/json" -uri $uri -headers $headers
if ($messages)
{
$sMessages = $messages.value | Sort-Object loggedDate
Expand All @@ -196,7 +204,7 @@ function ShowMessages($headers, $run)
}

function UploadTestDrop($testdrop, $src)
{
{
$dest = $testdrop.accessData.dropContainerUrl
$sas = $testdrop.accessData.sasKey

Expand Down Expand Up @@ -397,6 +405,7 @@ if ($drop.dropType -eq "TestServiceBlobDrop")

#Queue the test run
$runJson = ComposeTestRunJson $LoadTest $drop.id

$run = QueueTestRun $headers $runJson
MonitorAcquireResource $headers $run

Expand Down Expand Up @@ -468,5 +477,5 @@ else
Write-Error ("Connection '{0}' failed for service '{1}'" -f $connectedServiceName, $connectedServiceDetails.Url.AbsoluteUri)
}

WriteTaskMessages "Finished Load Test Script"
WriteTaskMessages "Load Test Script execution completed"

2 changes: 1 addition & 1 deletion Tasks/RunLoadTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 10
"Patch": 12
},
"demands": [
"msbuild",
Expand Down

0 comments on commit 2700f36

Please sign in to comment.