|
6 | 6 | #include <barrier> |
7 | 7 | #include <condition_variable> |
8 | 8 | #include <iostream> |
| 9 | +#include <memory> |
9 | 10 | #include <mutex> |
10 | 11 | #include <stdexcept> |
11 | 12 | #include <string_view> |
@@ -118,6 +119,10 @@ AwaitCheck(std::shared_ptr<UpdateCoordinator> coordinator, UpdateCheckReason rea |
118 | 119 | result = co_await coordinator->CheckForUpdatesAsync(reason); |
119 | 120 | } |
120 | 121 |
|
| 122 | +winrt::Windows::Foundation::IAsyncAction AwaitCheckTask(UpdateCheckTask task, UpdateCheckResult& result) { |
| 123 | + result = co_await task; |
| 124 | +} |
| 125 | + |
121 | 126 | winrt::Windows::Foundation::IAsyncAction AwaitAutomaticWindow(std::shared_ptr<UpdateCoordinator> coordinator, |
122 | 127 | bool& result) { |
123 | 128 | result = co_await coordinator->WaitForAutomaticCheckWindowAsync(1h); |
@@ -226,6 +231,25 @@ void TestShutdownWakesEveryAutomaticWindowWaiter() { |
226 | 231 | "shutdown must wake and cancel every automatic-window waiter"); |
227 | 232 | } |
228 | 233 |
|
| 234 | +void TestCheckRetainsCoordinatorUntilCompletion() { |
| 235 | + auto backend = std::make_shared<FakeUpdateBackend>(); |
| 236 | + auto coordinator = MakeCoordinator(backend); |
| 237 | + std::weak_ptr<UpdateCoordinator> weakCoordinator = coordinator; |
| 238 | + UpdateCheckResult result; |
| 239 | + { |
| 240 | + auto action = AwaitCheckTask(coordinator->CheckForUpdatesAsync(UpdateCheckReason::Manual), result); |
| 241 | + Check(backend->WaitForCalls(1), "lifetime check must start its backend flight"); |
| 242 | + |
| 243 | + coordinator.reset(); |
| 244 | + Check(!weakCoordinator.expired(), "an active update check must retain its coordinator"); |
| 245 | + backend->Release(0); |
| 246 | + action.get(); |
| 247 | + |
| 248 | + Check(result.Status == UpdateCheckStatus::UpToDate, "the retained update check must complete normally"); |
| 249 | + } |
| 250 | + Check(weakCoordinator.expired(), "the coordinator must be released after its final update check completes"); |
| 251 | +} |
| 252 | + |
229 | 253 | void TestParallelSingleFlightStress() { |
230 | 254 | constexpr size_t callerCount = 32; |
231 | 255 | auto backend = std::make_shared<FakeUpdateBackend>(); |
@@ -277,6 +301,7 @@ int RunUpdateCoordinatorTests() { |
277 | 301 | TestStableAutomaticWindowDeterministically(); |
278 | 302 | TestShutdownAndLateCompletion(); |
279 | 303 | TestShutdownWakesEveryAutomaticWindowWaiter(); |
| 304 | + TestCheckRetainsCoordinatorUntilCompletion(); |
280 | 305 | TestParallelSingleFlightStress(); |
281 | 306 | winrt::uninit_apartment(); |
282 | 307 | return g_failures; |
|
0 commit comments