Handle cases where CustomEvent was not initially sent (#11807)

This commit is contained in:
James Truher [MSFT]
2020-02-11 11:40:43 -08:00
committed by GitHub
parent 35c7b7842e
commit 4a0eda7fa9
2 changed files with 36 additions and 0 deletions
@@ -128,4 +128,29 @@ Describe "Telemetry for shell startup" -Tag CI {
$result = & $PWSH -NoProfile -Command '[Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry]::CanSendTelemetry'
$result | Should -Be $expectedValue
}
It "Should resend startup event if the semaphore says we haven't sent telemetry" {
$resultJson = & $PWSH -NoProfile -c {
$telemetryType = [Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry]
$bindingFlags = [System.Reflection.BindingFlags]"NonPublic,Static"
$initialValue = ${telemetryType}.GetMember("s_startupEventSent", $bindingFlags)[0].GetValue($null)
# force a resend of the startup telemetry
$null = ${telemetryType}.GetMember("s_startupEventSent", $bindingFlags)[0].SetValue($null,0)
$null = Get-Date | Out-String
# now check it again, it should be true now that something has executed
$finalValue = ${telemetryType}.GetMember("s_startupEventSent", $bindingFlags)[0].GetValue($null)
@{
initialValue = $initialValue
finalValue = $finalValue
} | ConvertTo-Json -Compress
}
$result = $resultJson | ConvertFrom-Json
$result.InitialValue | Should -Be 1 -Because "Should have sent telemetry on console startup"
$result.FinalValue | Should -Be 1 -Because "Should have resent telemetry"
}
}