session-ios/Loki/OnionRequestAPITests.swift

25 lines
888 B
Swift
Raw Normal View History

2020-04-03 01:34:05 +02:00
import CryptoSwift
2020-04-02 06:48:42 +02:00
import PromiseKit
@testable import SignalServiceKit
import XCTest
class OnionRequestAPITests : XCTestCase {
2020-04-24 01:16:06 +02:00
private let maxRetryCount: UInt = 2 // Be a bit more stringent when testing
private let testPublicKey = "0501da4723331eb54aaa9a6753a0a59f762103de63f1dc40879cb65a5b5f508814"
2020-04-02 06:48:42 +02:00
func testOnionRequestSending() {
let semaphore = DispatchSemaphore(value: 0)
2020-04-24 01:16:06 +02:00
var error: Error? = nil
LokiAPI.useOnionRequests = true
let _ = attempt(maxRetryCount: maxRetryCount, recoveringOn: LokiAPI.workQueue) { [testPublicKey = self.testPublicKey] in
LokiAPI.getSwarm(for: testPublicKey)
}.done(on: LokiAPI.workQueue) { _ in
2020-04-02 06:48:42 +02:00
semaphore.signal()
2020-04-24 01:16:06 +02:00
}.catch(on: LokiAPI.workQueue) {
error = $0; semaphore.signal()
2020-04-02 06:48:42 +02:00
}
semaphore.wait()
2020-04-24 01:16:06 +02:00
XCTAssert(error == nil)
2020-04-02 06:48:42 +02:00
}
}