Fix #667 Make no ack an enum case

This commit is contained in:
Erik 2017-05-05 22:35:39 -04:00
parent 58f51d07a2
commit 23c76417d2
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D
2 changed files with 41 additions and 11 deletions

View File

@ -9,18 +9,43 @@
import XCTest
@testable import SocketIO
class SocketAckManagerTest: XCTestCase {
class SocketAckManagerTest : XCTestCase {
var ackManager = SocketAckManager()
func testAddAcks() {
let callbackExpection = self.expectation(description: "callbackExpection")
let callbackExpection = expectation(description: "callbackExpection")
let itemsArray = ["Hi", "ho"]
func callback(_ items: [Any]) {
callbackExpection.fulfill()
}
ackManager.addAck(1, callback: callback)
ackManager.executeAck(1, with: itemsArray, onQueue: DispatchQueue.main)
waitForExpectations(timeout: 3.0, handler: nil)
}
func testManagerTimeoutAck() {
let callbackExpection = expectation(description: "Manager should timeout ack with noAck status")
let itemsArray = ["Hi", "ho"]
func callback(_ items: [Any]) {
XCTAssertEqual(items.count, 1, "Timed out ack should have one value")
guard let timeoutReason = items[0] as? String else {
XCTFail("Timeout reason should be a string")
return
}
XCTAssertEqual(timeoutReason, SocketAckStatus.noAck.rawValue)
callbackExpection.fulfill()
}
ackManager.addAck(1, callback: callback)
ackManager.timeoutAck(1, onQueue: DispatchQueue.main)
waitForExpectations(timeout: 0.2, handler: nil)
}
}

View File

@ -22,8 +22,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import Dispatch
import Foundation
public enum SocketAckStatus : String {
case noAck = "NO ACK"
}
private struct SocketAck : Hashable {
let ack: Int
var callback: AckCallback!
@ -73,7 +78,7 @@ struct SocketAckManager {
let ack = acks.remove(SocketAck(ack: ack))
onQueue.async() {
ack?.callback?(["NO ACK"])
ack?.callback?([SocketAckStatus.noAck.rawValue])
}
}
}