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

Merge branch 'fix/messener-wait-for-nodes-sleep' into 'development'

Fix sleep interval in MessengerWaitForNodes

See merge request elixxir/elixxir-dapps-sdk-swift!38
parents 3c8cc6bd abd0401f
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 XXClient
import XCTestDynamicOverlay import XCTestDynamicOverlay
...@@ -9,21 +10,21 @@ public struct MessengerWaitForNodes { ...@@ -9,21 +10,21 @@ public struct MessengerWaitForNodes {
case timeout 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( public func callAsFunction(
targetRatio: Double = 0.8, targetRatio: Double = 0.8,
sleepMS: Int = 1_000, sleepInterval: TimeInterval = 1,
retries: Int = 10, retries: Int = 10,
onProgress: @escaping Progress = { _ in } onProgress: @escaping Progress = { _ in }
) throws { ) throws {
try run(targetRatio, sleepMS, retries, onProgress) try run(targetRatio, sleepInterval, retries, onProgress)
} }
} }
extension MessengerWaitForNodes { extension MessengerWaitForNodes {
public static func live(_ env: MessengerEnvironment) -> 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 { guard let cMix = env.cMix() else {
throw Error.notLoaded throw Error.notLoaded
} }
...@@ -33,7 +34,7 @@ extension MessengerWaitForNodes { ...@@ -33,7 +34,7 @@ extension MessengerWaitForNodes {
onProgress(report) onProgress(report)
while report.ratio < targetRatio && retries > 0 { while report.ratio < targetRatio && retries > 0 {
env.sleep(sleepMS) env.sleep(sleepInterval)
report = try cMix.getNodeRegistrationStatus() report = try cMix.getNodeRegistrationStatus()
retries -= 1 retries -= 1
onProgress(report) onProgress(report)
......
...@@ -17,7 +17,7 @@ public struct MessengerEnvironment { ...@@ -17,7 +17,7 @@ public struct MessengerEnvironment {
public var newCMix: NewCMix public var newCMix: NewCMix
public var newOrLoadUd: NewOrLoadUd public var newOrLoadUd: NewOrLoadUd
public var passwordStorage: PasswordStorage public var passwordStorage: PasswordStorage
public var sleep: (Int) -> Void public var sleep: (TimeInterval) -> Void
public var storageDir: String public var storageDir: String
public var ud: Stored<UserDiscovery?> public var ud: Stored<UserDiscovery?>
public var udAddress: String? public var udAddress: String?
...@@ -48,7 +48,7 @@ extension MessengerEnvironment { ...@@ -48,7 +48,7 @@ extension MessengerEnvironment {
newCMix: .live, newCMix: .live,
newOrLoadUd: .live, newOrLoadUd: .live,
passwordStorage: .keychain, passwordStorage: .keychain,
sleep: { Foundation.sleep(UInt32($0)) }, sleep: { Thread.sleep(forTimeInterval: $0) },
storageDir: MessengerEnvironment.defaultStorageDir, storageDir: MessengerEnvironment.defaultStorageDir,
ud: .inMemory(), ud: .inMemory(),
udAddress: nil, udAddress: nil,
......
...@@ -32,7 +32,7 @@ final class MessengerWaitForNodesTests: XCTestCase { ...@@ -32,7 +32,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
try waitForNodes( try waitForNodes(
targetRatio: 0.7, targetRatio: 0.7,
sleepMS: 123, sleepInterval: 123,
retries: 3, retries: 3,
onProgress: { didProgress.append($0) } onProgress: { didProgress.append($0) }
) )
...@@ -43,7 +43,7 @@ final class MessengerWaitForNodesTests: XCTestCase { ...@@ -43,7 +43,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
} }
func testWaitForTargetRatio() throws { func testWaitForTargetRatio() throws {
var didSleep: [Int] = [] var didSleep: [TimeInterval] = []
var didProgress: [NodeRegistrationReport] = [] var didProgress: [NodeRegistrationReport] = []
var reports: [NodeRegistrationReport] = [ var reports: [NodeRegistrationReport] = [
...@@ -63,7 +63,7 @@ final class MessengerWaitForNodesTests: XCTestCase { ...@@ -63,7 +63,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
try waitForNodes( try waitForNodes(
targetRatio: 0.7, targetRatio: 0.7,
sleepMS: 123, sleepInterval: 123,
retries: 3, retries: 3,
onProgress: { didProgress.append($0) } onProgress: { didProgress.append($0) }
) )
...@@ -77,7 +77,7 @@ final class MessengerWaitForNodesTests: XCTestCase { ...@@ -77,7 +77,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
} }
func testWaitTimeout() { func testWaitTimeout() {
var didSleep: [Int] = [] var didSleep: [TimeInterval] = []
var didProgress: [NodeRegistrationReport] = [] var didProgress: [NodeRegistrationReport] = []
var reports: [NodeRegistrationReport] = [ var reports: [NodeRegistrationReport] = [
...@@ -98,7 +98,7 @@ final class MessengerWaitForNodesTests: XCTestCase { ...@@ -98,7 +98,7 @@ final class MessengerWaitForNodesTests: XCTestCase {
XCTAssertThrowsError(try waitForNodes( XCTAssertThrowsError(try waitForNodes(
targetRatio: 0.7, targetRatio: 0.7,
sleepMS: 123, sleepInterval: 123,
retries: 3, retries: 3,
onProgress: { didProgress.append($0) } onProgress: { didProgress.append($0) }
)) { error in )) { 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