From d102867c6dec633aa2cc4533962ac38f70cc0de2 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Thu, 26 Oct 2023 18:46:31 -0300 Subject: [PATCH] Fix flaky test by inserting a mega yield --- Sources/_Helpers/Task.swift | 17 +++++++++++++++++ Tests/GoTrueTests/GoTrueClientTests.swift | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 Sources/_Helpers/Task.swift diff --git a/Sources/_Helpers/Task.swift b/Sources/_Helpers/Task.swift new file mode 100644 index 00000000..24bc6344 --- /dev/null +++ b/Sources/_Helpers/Task.swift @@ -0,0 +1,17 @@ +// +// File.swift +// +// +// Created by Guilherme Souza on 26/10/23. +// + +import Foundation + +extension Task where Success == Never, Failure == Never { + @_spi(Internal) + public static func megaYield(count: Int = 20) async { + for _ in 0...detached(priority: .background) { await Task.yield() }.value + } + } +} diff --git a/Tests/GoTrueTests/GoTrueClientTests.swift b/Tests/GoTrueTests/GoTrueClientTests.swift index 854682cf..657061dc 100644 --- a/Tests/GoTrueTests/GoTrueClientTests.swift +++ b/Tests/GoTrueTests/GoTrueClientTests.swift @@ -45,6 +45,8 @@ final class GoTrueClientTests: XCTestCase { streamTask.cancel() + await Task.megaYield() + listeners = await sut.authChangeListeners XCTAssertEqual(listeners.count, 0) }