From d1f5a375200ae5ebe357d8f76ac4dd3a3d6712e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 29 Sep 2024 15:46:18 +0200 Subject: [PATCH] Enhance the demo app tests Based on https://forums.swift.org/t/testing-closure-based-asynchronous-apis/73705/36 --- .../GRDBDemo/GRDBDemoTests/PlayerListModelTests.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemoTests/PlayerListModelTests.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemoTests/PlayerListModelTests.swift index 18c386a44..80493f1ed 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemoTests/PlayerListModelTests.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemoTests/PlayerListModelTests.swift @@ -18,7 +18,7 @@ struct PlayerListModelTests { // Then the model eventually fetches the player. // We poll because we do not know when the model will update its players. - await pollUntil { + try await pollUntil { model.players.isEmpty == false } #expect(model.players == [player]) @@ -37,7 +37,7 @@ struct PlayerListModelTests { // Then the model eventually fetches the player. // We poll because we do not know when the model will update its players. - await pollUntil { + try await pollUntil { model.players.isEmpty == false } #expect(model.players == [player]) @@ -68,14 +68,14 @@ struct PlayerListModelTests { } /// Convenience method that loops until a condition is met. - private func pollUntil(condition: @escaping @MainActor () async -> Bool) async { - await confirmation { confirmation in + private func pollUntil(condition: @escaping @MainActor () async -> Bool) async throws { + try await confirmation { confirmation in while true { if await condition() { confirmation() return } else { - await Task.yield() + try await Task.sleep(for: .seconds(0.01)) } } }