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

Update MessengerDestroy

- stop network follower if running
- wait until cMix has no running processes
parent 31894e1a
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!58Update MessengerDestroy
...@@ -11,6 +11,16 @@ public struct MessengerDestroy { ...@@ -11,6 +11,16 @@ public struct MessengerDestroy {
extension MessengerDestroy { extension MessengerDestroy {
public static func live(_ env: MessengerEnvironment) -> MessengerDestroy { public static func live(_ env: MessengerEnvironment) -> MessengerDestroy {
MessengerDestroy { MessengerDestroy {
if let cMix = env.cMix() {
if cMix.networkFollowerStatus() == .running {
try cMix.stopNetworkFollower()
}
var hasRunningProcesses = cMix.hasRunningProcesses()
while hasRunningProcesses {
env.sleep(1)
hasRunningProcesses = cMix.hasRunningProcesses()
}
}
env.ud.set(nil) env.ud.set(nil)
env.e2e.set(nil) env.e2e.set(nil)
env.cMix.set(nil) env.cMix.set(nil)
......
...@@ -6,12 +6,23 @@ import XXClient ...@@ -6,12 +6,23 @@ import XXClient
final class MessengerDestroyTests: XCTestCase { final class MessengerDestroyTests: XCTestCase {
func testDestroy() throws { func testDestroy() throws {
let storageDir = "test-storage-dir" let storageDir = "test-storage-dir"
var hasRunningProcesses: [Bool] = [true, true, false]
var didStopNetworkFollower = 0
var didSleep: [TimeInterval] = []
var didRemoveDirectory: [String] = [] var didRemoveDirectory: [String] = []
var didSetUD: [UserDiscovery?] = [] var didSetUD: [UserDiscovery?] = []
var didSetE2E: [E2E?] = [] var didSetE2E: [E2E?] = []
var didSetCMix: [CMix?] = [] var didSetCMix: [CMix?] = []
var env: MessengerEnvironment = .unimplemented var env: MessengerEnvironment = .unimplemented
env.cMix.get = {
var cMix: CMix = .unimplemented
cMix.networkFollowerStatus.run = { .running }
cMix.stopNetworkFollower.run = { didStopNetworkFollower += 1 }
cMix.hasRunningProcesses.run = { hasRunningProcesses.removeFirst() }
return cMix
}
env.sleep = { didSleep.append($0) }
env.storageDir = storageDir env.storageDir = storageDir
env.ud.set = { didSetUD.append($0) } env.ud.set = { didSetUD.append($0) }
env.e2e.set = { didSetE2E.append($0) } env.e2e.set = { didSetE2E.append($0) }
...@@ -21,12 +32,31 @@ final class MessengerDestroyTests: XCTestCase { ...@@ -21,12 +32,31 @@ final class MessengerDestroyTests: XCTestCase {
try destroy() try destroy()
XCTAssertNoDifference(didStopNetworkFollower, 1)
XCTAssertNoDifference(didSleep, [1, 1])
XCTAssertNoDifference(didSetUD.map { $0 == nil }, [true]) XCTAssertNoDifference(didSetUD.map { $0 == nil }, [true])
XCTAssertNoDifference(didSetE2E.map { $0 == nil }, [true]) XCTAssertNoDifference(didSetE2E.map { $0 == nil }, [true])
XCTAssertNoDifference(didSetCMix.map { $0 == nil }, [true]) XCTAssertNoDifference(didSetCMix.map { $0 == nil }, [true])
XCTAssertNoDifference(didRemoveDirectory, [storageDir]) XCTAssertNoDifference(didRemoveDirectory, [storageDir])
} }
func testStopNetworkFollowerFailure() {
struct Error: Swift.Error, Equatable {}
let error = Error()
var env: MessengerEnvironment = .unimplemented
env.cMix.get = {
var cMix: CMix = .unimplemented
cMix.networkFollowerStatus.run = { .running }
cMix.stopNetworkFollower.run = { throw error }
return cMix
}
let destroy: MessengerDestroy = .live(env)
XCTAssertThrowsError(try destroy()) { err in
XCTAssertEqual(err as? Error, error)
}
}
func testRemoveDirectoryFailure() { func testRemoveDirectoryFailure() {
struct Error: Swift.Error, Equatable {} struct Error: Swift.Error, Equatable {}
let error = Error() let error = Error()
...@@ -35,6 +65,7 @@ final class MessengerDestroyTests: XCTestCase { ...@@ -35,6 +65,7 @@ final class MessengerDestroyTests: XCTestCase {
var didSetCMix: [CMix?] = [] var didSetCMix: [CMix?] = []
var env: MessengerEnvironment = .unimplemented var env: MessengerEnvironment = .unimplemented
env.cMix.get = { nil }
env.ud.set = { didSetUD.append($0) } env.ud.set = { didSetUD.append($0) }
env.e2e.set = { didSetE2E.append($0) } env.e2e.set = { didSetE2E.append($0) }
env.cMix.set = { didSetCMix.append($0) } env.cMix.set = { didSetCMix.append($0) }
......
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