mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Handle cases where CustomEvent was not initially sent (#11807)
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user