Skip to content

Commit

Permalink
Fix flaky test by inserting a mega yield
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Oct 26, 2023
1 parent 6e79b0c commit d102867
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/_Helpers/Task.swift
Original file line number Diff line number Diff line change
@@ -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..<count {
await Task<Void, Never>.detached(priority: .background) { await Task.yield() }.value
}
}
}
2 changes: 2 additions & 0 deletions Tests/GoTrueTests/GoTrueClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ final class GoTrueClientTests: XCTestCase {

streamTask.cancel()

await Task.megaYield()

listeners = await sut.authChangeListeners
XCTAssertEqual(listeners.count, 0)
}
Expand Down

0 comments on commit d102867

Please sign in to comment.