Skip to content
Snippets Groups Projects
Commit abd0401f authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Fix sleep interval in MessengerWaitForNodes

parent 3c8cc6bd
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!38Fix sleep interval in MessengerWaitForNodes
import Foundation
import XXClient
import XCTestDynamicOverlay
......@@ -9,21 +10,21 @@ public struct MessengerWaitForNodes {
case timeout
}
public var run: (Double, Int, Int, @escaping Progress) throws -> Void
public var run: (Double, TimeInterval, Int, @escaping Progress) throws -> Void
public func callAsFunction(
targetRatio: Double = 0.8,
sleepMS: Int = 1_000,
sleepInterval: TimeInterval = 1,
retries: Int = 10,
onProgress: @escaping Progress = { _ in }
) throws {
try run(targetRatio, sleepMS, retries, onProgress)
try run(targetRatio, sleepInterval, retries, onProgress)
}
}
extension MessengerWaitForNodes {
public static func live(_ env: MessengerEnvironment) -> MessengerWaitForNodes {
MessengerWaitForNodes { targetRatio, sleepMS, retries, onProgress in
MessengerWaitForNodes { targetRatio, sleepInterval, retries, onProgress in
guard let cMix = env.cMix() else {
throw Error.notLoaded
}
......@@ -33,7 +34,7 @@ extension MessengerWaitForNodes {
onProgress(report)
while report.ratio < targetRatio && retries > 0 {
env.sleep(sleepMS)
env.sleep(sleepInterval)
report = try cMix.getNodeRegistrationStatus()
retries -= 1
onProgress(report)
......
......@@ -17,7 +17,7 @@ public struct MessengerEnvironment {
public var newCMix: NewCMix
public var newOrLoadUd: NewOrLoadUd
public var passwordStorage: PasswordStorage
public var sleep: (Int) -> Void
public var sleep: (TimeInterval) -> Void
public var storageDir: String
public var ud: Stored<UserDiscovery?>
public var udAddress: String?
......@@ -48,7 +48,7 @@ extension MessengerEnvironment {
newCMix: .live,
newOrLoadUd: .live,
passwordStorage: .keychain,
sleep: { Foundation.sleep(UInt32($0)) },
sleep: { Thread.sleep(forTimeInterval: $0) },
storageDir: MessengerEnvironment.defaultStorageDir,
ud: .inMemory(),
udAddress: nil,
......
......@@ -32,7 +32,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
try waitForNodes(
targetRatio: 0.7,
sleepMS: 123,
sleepInterval: 123,
retries: 3,
onProgress: { didProgress.append($0) }
)
......@@ -43,7 +43,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
}
func testWaitForTargetRatio() throws {
var didSleep: [Int] = []
var didSleep: [TimeInterval] = []
var didProgress: [NodeRegistrationReport] = []
var reports: [NodeRegistrationReport] = [
......@@ -63,7 +63,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
try waitForNodes(
targetRatio: 0.7,
sleepMS: 123,
sleepInterval: 123,
retries: 3,
onProgress: { didProgress.append($0) }
)
......@@ -77,7 +77,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
}
func testWaitTimeout() {
var didSleep: [Int] = []
var didSleep: [TimeInterval] = []
var didProgress: [NodeRegistrationReport] = []
var reports: [NodeRegistrationReport] = [
......@@ -98,7 +98,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
XCTAssertThrowsError(try waitForNodes(
targetRatio: 0.7,
sleepMS: 123,
sleepInterval: 123,
retries: 3,
onProgress: { didProgress.append($0) }
)) { error in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment