From 1b31432de9c2cfbc3db396879021650208f00f05 Mon Sep 17 00:00:00 2001 From: gmbnt Date: Mon, 30 Mar 2020 13:32:51 +1100 Subject: [PATCH] Stub onion request path building test --- .../Loki/API/Onion Requests/OnionRequestAPI.swift | 4 ++-- .../API/Onion Requests/OnionRequestAPITests.swift | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index 08fd5e2cd..5ac7e63d2 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -1,8 +1,8 @@ import PromiseKit internal enum OnionRequestAPI { - private static let workQueue = DispatchQueue.global() // TODO: We should probably move away from using the global queue for this - + /// - Note: Exposed for testing purposes. + internal static let workQueue = DispatchQueue.global() // TODO: We should probably move away from using the global queue for this internal static var guardSnodes: Set = [] internal static var paths: Set = [] diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPITests.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPITests.swift index 671f85af5..f430c69b6 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPITests.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPITests.swift @@ -2,5 +2,19 @@ import XCTest class OnionRequestAPITests : XCTestCase { + private let maxRetryCount: UInt = 2 // Be a bit more stringent when testing + // TODO: Remove dependency on SSKEnvironment + + func testGetPath() { + let semaphore = DispatchSemaphore(value: 0) + var error: Error? = nil + let _ = OnionRequestAPI.getPath().retryingIfNeeded(maxRetryCount: maxRetryCount).done(on: OnionRequestAPI.workQueue) { _ in + semaphore.signal() + }.catch(on: OnionRequestAPI.workQueue) { + error = $0; semaphore.signal() + } + semaphore.wait() + XCTAssert(error == nil) + } }