|
78 | 78 | return $text | ConvertFrom-Json |
79 | 79 | } |
80 | 80 |
|
| 81 | + function Wait-ForCliCondition { |
| 82 | + param( |
| 83 | + [Parameter(Mandatory = $true)] |
| 84 | + [string[]] $Arguments, |
| 85 | + [Parameter(Mandatory = $true)] |
| 86 | + [scriptblock] $Condition, |
| 87 | + [Parameter(Mandatory = $true)] |
| 88 | + [string] $FailureMessage, |
| 89 | + [int] $TimeoutSeconds = 90, |
| 90 | + [int] $DelaySeconds = 3 |
| 91 | + ) |
| 92 | + |
| 93 | + $deadline = (Get-Date).AddSeconds($TimeoutSeconds) |
| 94 | + $lastResponse = $null |
| 95 | + |
| 96 | + do { |
| 97 | + $lastResponse = Invoke-CliJson -Arguments $Arguments |
| 98 | + if (& $Condition $lastResponse) { |
| 99 | + return $lastResponse |
| 100 | + } |
| 101 | + |
| 102 | + Start-Sleep -Seconds $DelaySeconds |
| 103 | + } while ((Get-Date) -lt $deadline) |
| 104 | + |
| 105 | + throw "$FailureMessage`nLast payload: $($lastResponse | ConvertTo-Json -Depth 8)" |
| 106 | + } |
| 107 | + |
81 | 108 | $deadline = (Get-Date).AddMinutes(2) |
82 | 109 | do { |
83 | 110 | Start-Sleep -Seconds 2 |
@@ -106,53 +133,69 @@ try { |
106 | 133 | throw "install-package failed: $($install | ConvertTo-Json -Depth 8)" |
107 | 134 | } |
108 | 135 |
|
109 | | - $installed = Invoke-CliJson -Arguments @('list-installed', '--manager', '.NET Tool') |
| 136 | + $installed = Wait-ForCliCondition ` |
| 137 | + -Arguments @('list-installed', '--manager', '.NET Tool') ` |
| 138 | + -FailureMessage 'list-installed did not include dotnetsay after installation' ` |
| 139 | + -Condition { |
| 140 | + param($response) |
| 141 | + @($response.packages | Where-Object { $_.id -eq 'dotnetsay' }).Count -gt 0 |
| 142 | + } |
110 | 143 | $installedDotnetsay = @($installed.packages | Where-Object { $_.id -eq 'dotnetsay' }) |
111 | | - if ($installedDotnetsay.Count -eq 0) { |
112 | | - throw "list-installed did not include dotnetsay after installation" |
113 | | - } |
114 | 144 |
|
115 | | - if (-not ($installedDotnetsay.version -contains '2.1.4')) { |
116 | | - throw "Expected dotnetsay version 2.1.4 after install. Found: $($installedDotnetsay.version -join ', ')" |
117 | | - } |
| 145 | + $installed = Wait-ForCliCondition ` |
| 146 | + -Arguments @('list-installed', '--manager', '.NET Tool') ` |
| 147 | + -FailureMessage 'dotnetsay did not report version 2.1.4 after installation' ` |
| 148 | + -Condition { |
| 149 | + param($response) |
| 150 | + @($response.packages | Where-Object { $_.id -eq 'dotnetsay' -and $_.version -eq '2.1.4' }).Count -gt 0 |
| 151 | + } |
| 152 | + $installedDotnetsay = @($installed.packages | Where-Object { $_.id -eq 'dotnetsay' }) |
118 | 153 |
|
119 | | - $updates = Invoke-CliJson -Arguments @('get-updates', '--manager', '.NET Tool') |
| 154 | + $updates = Wait-ForCliCondition ` |
| 155 | + -Arguments @('get-updates', '--manager', '.NET Tool') ` |
| 156 | + -FailureMessage 'get-updates did not report dotnetsay after installing 2.1.4' ` |
| 157 | + -Condition { |
| 158 | + param($response) |
| 159 | + @($response.updates | Where-Object { $_.id -eq 'dotnetsay' }).Count -gt 0 |
| 160 | + } |
120 | 161 | $updatableDotnetsay = @($updates.updates | Where-Object { $_.id -eq 'dotnetsay' }) |
121 | | - if ($updatableDotnetsay.Count -eq 0) { |
122 | | - throw "get-updates did not report dotnetsay after installing 2.1.4" |
123 | | - } |
124 | 162 |
|
125 | 163 | $update = Invoke-CliJson -Arguments @('update-package', '--manager', '.NET Tool', '--package-id', 'dotnetsay') |
126 | 164 | if ($update.status -ne 'success') { |
127 | 165 | throw "update-package failed: $($update | ConvertTo-Json -Depth 8)" |
128 | 166 | } |
129 | 167 |
|
130 | | - $installedAfterUpdate = Invoke-CliJson -Arguments @('list-installed', '--manager', '.NET Tool') |
| 168 | + $installedAfterUpdate = Wait-ForCliCondition ` |
| 169 | + -Arguments @('list-installed', '--manager', '.NET Tool') ` |
| 170 | + -FailureMessage 'list-installed did not include an updated dotnetsay version after update' ` |
| 171 | + -Condition { |
| 172 | + param($response) |
| 173 | + @($response.packages | Where-Object { $_.id -eq 'dotnetsay' -and $_.version -ne '2.1.4' }).Count -gt 0 |
| 174 | + } |
131 | 175 | $updatedDotnetsay = @($installedAfterUpdate.packages | Where-Object { $_.id -eq 'dotnetsay' }) |
132 | | - if ($updatedDotnetsay.Count -eq 0) { |
133 | | - throw "list-installed did not include dotnetsay after update" |
134 | | - } |
135 | 176 |
|
136 | | - if ($updatedDotnetsay.version -contains '2.1.4') { |
137 | | - throw "dotnetsay still reports version 2.1.4 after update" |
138 | | - } |
139 | | - |
140 | | - $updatesAfterUpdate = Invoke-CliJson -Arguments @('get-updates', '--manager', '.NET Tool') |
| 177 | + $updatesAfterUpdate = Wait-ForCliCondition ` |
| 178 | + -Arguments @('get-updates', '--manager', '.NET Tool') ` |
| 179 | + -FailureMessage 'dotnetsay still appears in get-updates after update' ` |
| 180 | + -Condition { |
| 181 | + param($response) |
| 182 | + @($response.updates | Where-Object { $_.id -eq 'dotnetsay' }).Count -eq 0 |
| 183 | + } |
141 | 184 | $remainingDotnetsayUpdate = @($updatesAfterUpdate.updates | Where-Object { $_.id -eq 'dotnetsay' }) |
142 | | - if ($remainingDotnetsayUpdate.Count -ne 0) { |
143 | | - throw "dotnetsay still appears in get-updates after update" |
144 | | - } |
145 | 185 |
|
146 | 186 | $uninstall = Invoke-CliJson -Arguments @('uninstall-package', '--manager', '.NET Tool', '--package-id', 'dotnetsay', '--scope', 'Global') |
147 | 187 | if ($uninstall.status -ne 'success') { |
148 | 188 | throw "uninstall-package failed: $($uninstall | ConvertTo-Json -Depth 8)" |
149 | 189 | } |
150 | 190 |
|
151 | | - $installedAfterUninstall = Invoke-CliJson -Arguments @('list-installed', '--manager', '.NET Tool') |
| 191 | + $installedAfterUninstall = Wait-ForCliCondition ` |
| 192 | + -Arguments @('list-installed', '--manager', '.NET Tool') ` |
| 193 | + -FailureMessage 'dotnetsay still appears in list-installed after uninstall' ` |
| 194 | + -Condition { |
| 195 | + param($response) |
| 196 | + @($response.packages | Where-Object { $_.id -eq 'dotnetsay' }).Count -eq 0 |
| 197 | + } |
152 | 198 | $remainingDotnetsay = @($installedAfterUninstall.packages | Where-Object { $_.id -eq 'dotnetsay' }) |
153 | | - if ($remainingDotnetsay.Count -ne 0) { |
154 | | - throw "dotnetsay still appears in list-installed after uninstall" |
155 | | - } |
156 | 199 | } |
157 | 200 | finally { |
158 | 201 | Stop-Daemon |
|
0 commit comments