Public/Get-CloudLoadTestRunSummary.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Function Get-CloudLoadTestRunSummary{
[cmdletbinding()]
Param(

    [Parameter(Mandatory=$True)]
    [hashtable]
    $Headers,

    [Parameter(Mandatory=$True)]
    [ValidateScript({
      # Check if valid Uri
        $IsValidUri = [system.uri]::IsWellFormedUriString($_,[System.UriKind]::Absolute)
        if ($IsVAlidUri -eq $True){
            return $True
        }
        else{
            throw "Parameter value is not valid '$_'"
        }
    })] 
    [string]
    $BaseUri,

    [Parameter(Mandatory=$True)]
    [guid]
    $TestRunId,

    [Parameter(Mandatory=$False)]
    [bool]
    $OutputTeamCityServiceMessages = $False

)

    try{
        $Uri = "$BaseUri/{0}/{1}/ResultSummary" -f "_apis/clt/testruns", $TestRunId
        $Response = Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers


        Write-Verbose ("Overall Scenario Summary: minUserLoad = {0}, maxUserLoad = {1}" -f $Response.overallScenarioSummary.minUserLoad, $Response.overallScenarioSummary.maxUserLoad)

        Write-Verbose ("Overall Test Summary: totalTests = {0}, passedTests = {1}, failedTests = {2}, averageTestTime = {3}" -f $Response.overallTestSummary.totalTests, $Response.overallTestSummary.passedTests, $Response.overallTestSummary.failedTests, $Response.overallTestSummary.averageTestTime )

        Write-Verbose ("Overall Page Summary: totalPages = {0}, percentagePagesMeetingGoal = {1}, averagePageTime = {2}, averageTestTime = {3}" -f $Response.overallPageSummary.totalPages, $Response.overallPageSummary.percentagePagesMeetingGoal, $Response.overallPageSummary.failedTests, $Response.overallPageSummary.averagePageTime )

        Write-Verbose ("Overall Request Summary: totalRequests = {0}, passedRequests = {1}, failedRequests = {2}, averageResponseTime = {3}, requestsPerSec = {4}" -f $Response.overallRequestSummary.totalRequests, $Response.overallRequestSummary.passedRequests, $Response.overallRequestSummary.failedRequests, $Response.overallRequestSummary.averageResponseTime, $Response.overallRequestSummary.requestsPerSec )


        if ($OutputTeamCityServiceMessages -eq $True){

            # Output OverallRequestSummary
            Write-Host ("##teamcity[buildStatisticValue key='OverallRequestSummary-TotalRequests' value='{0}']" -f $Response.overallRequestSummary.totalRequests )
            Write-Host ("##teamcity[buildStatisticValue key='OverallRequestSummary-PassedRequests' value='{0}']" -f $Response.overallRequestSummary.passedRequests )
            Write-Host ("##teamcity[buildStatisticValue key='OverallRequestSummary-FailedRequests' value='{0}']" -f $Response.overallRequestSummary.failedRequests )
            Write-Host ("##teamcity[buildStatisticValue key='OverallRequestSummary-AverageResponseTime' value='{0}']" -f ($Response.overallRequestSummary.averageResponseTime * 1000) )
            Write-Host ("##teamcity[buildStatisticValue key='OverallRequestSummary-RequestsPerSec' value='{0}']" -f [math]::Round($Response.overallRequestSummary.requestsPerSec,1) )

            # Output overallTestSummary
            Write-Host ("##teamcity[buildStatisticValue key='OverallTestSummary-TotalTests' value='{0}']" -f $Response.overallTestSummary.totalTests )
            Write-Host ("##teamcity[buildStatisticValue key='OverallTestSummary-PassedTests' value='{0}']" -f $Response.overallTestSummary.passedTests )
            Write-Host ("##teamcity[buildStatisticValue key='OverallTestSummary-FailedTests' value='{0}']" -f $Response.overallTestSummary.failedTests )
            Write-Host ("##teamcity[buildStatisticValue key='OverallTestSummary-AverageTestTime' value='{0}']" -f ($Response.overallTestSummary.averageTestTime * 1000) )

            # Output overallPageSummary
            Write-Host ("##teamcity[buildStatisticValue key='OverallPageSummary-TotalPages' value='{0}']" -f $Response.overallPageSummary.totalPages )
            Write-Host ("##teamcity[buildStatisticValue key='OverallPageSummary-PercentagePagesMeetingGoal' value='{0}']" -f $Response.overallPageSummary.percentagePagesMeetingGoal )
            Write-Host ("##teamcity[buildStatisticValue key='OverallPageSummary-AveragePageTime' value='{0}']" -f ($Response.overallPageSummary.averagePageTime * 1000) )

        }

        # Output top slow pages
        foreach ($SlowPage in $Response.topSlowPages){
            Write-Verbose ("Top Slow Pages: testName = {0}, pageUrl = '{1}', totalPages = {2}, percentagePagesMeetingGoal = {3}, averagePageTime = {4}" -f $SlowPage.testName, $SlowPage.pageUrl, $SlowPage.totalPages, $SlowPage.percentagePagesMeetingGoal, $SlowPage.averagePageTime)
            foreach ($PercentileData in $SlowPage.percentileData){
                Write-Verbose ("Top Slow Pages Percentile Data: testName = {0}, percentile = {1}, percentileValue = {2}" -f $SlowPage.testName, $PercentileData.percentile, $PercentileData.percentileValue)
                if ($OutputTeamCityServiceMessages -eq $True){
                    Write-Host ("##teamcity[buildStatisticValue key='TopSlowPages-{0}-{1}-percentile' value='{2}']" -f $SlowPage.testName, $PercentileData.percentile, $PercentileData.percentileValue)
                }
            }
        } 

        # Output top slow tests
        foreach ($SlowTest in $Response.topSlowTests){
            Write-Verbose ("Top Slow Tests: testName = {0}, totalTests = '{1}', passedTests = {2}, failedTests = {3}, averageTestTime = {4}" -f $SlowTest.testName, $SlowTest.totalTests, $SlowTest.passedTests, $SlowTest.failedTests, $SlowTest.averageTestTime)            
            foreach ($PercentileData in $SlowTest.percentileData){
                Write-Verbose ("Top Slow Tests Percentile Data: testName = {0}, percentile = {1}, percentileValue = {2}" -f $SlowTest.testName, $PercentileData.percentile, $PercentileData.percentileValue)
                if ($OutputTeamCityServiceMessages -eq $True){
                    Write-Host ("##teamcity[buildStatisticValue key='TopSlowTests-{0}-{1}-percentile' value='{2}']" -f $SlowTest.testName, $PercentileData.percentile, $PercentileData.percentileValue)
                }
            }
        }

        Return $Response

    }
    catch{
        throw $_
    }

}