Fix Tests than need to call the async TestCoordinator build function

This commit is contained in:
Francisco Gindre 2022-10-31 10:17:48 -03:00
parent 01d85f5748
commit 1c8e06742a
2 changed files with 52 additions and 14 deletions

View File

@ -11,7 +11,7 @@ import XCTest
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping type_body_length
//@MainActor
class AdvancedReOrgTests: XCTestCase {
class AdvancedReOrgTests: XCAsyncTestCase {
// TODO: Parameterize this from environment?
// swiftlint:disable:next line_length
var seedPhrase = "still champion voice habit trend flight survey between bitter process artefact blind carbon truly provide dizzy crush flush breeze blouse charge solid fish spread"
@ -31,22 +31,18 @@ class AdvancedReOrgTests: XCTestCase {
let branchID = "2bb40e60"
let chainName = "main"
let network = DarksideWalletDNetwork()
override func setUpWithError() throws {
try super.setUpWithError()
Task{ @MainActor [self] in
self.coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday + 50, //don't use an exact birthday, users never do.
channelProvider: ChannelProvider(),
network: network
)
}
override func asyncSetUpWithError() async throws {
self.coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday + 50, //don't use an exact birthday, users never do.
channelProvider: ChannelProvider(),
network: network
)
try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
}
override func tearDownWithError() throws {
try super.tearDownWithError()
override func asyncTearDownWithError() async throws {
NotificationCenter.default.removeObserver(self)
try coordinator.stop()
try? FileManager.default.removeItem(at: coordinator.databases.cacheDB)

View File

@ -0,0 +1,42 @@
//
// XCAsyncTestCase.swift
//
//
// credits: https://betterprogramming.pub/async-setup-and-teardown-in-xctestcase-dc7a2cdb9fb
//
///
/// A subclass of ``XCTestCase`` that supports async setup and teardown.
///
import Foundation
import XCTest
class XCAsyncTestCase: XCTestCase {
func asyncSetUpWithError() async throws {
fatalError("Must override")
}
func asyncTearDownWithError() async throws {
fatalError("Must override")
}
override func setUpWithError() throws {
wait {
try await self.asyncSetUpWithError()
}
}
override func tearDownWithError() throws {
wait {
try await self.asyncTearDownWithError()
}
}
func wait(asyncBlock: @escaping (() async throws -> Void)) {
let semaphore = DispatchSemaphore(value: 0)
Task.init {
try await asyncBlock()
semaphore.signal()
}
semaphore.wait()
}
}