2018-08-16 02:27:48 +00:00
|
|
|
//
|
|
|
|
// TuskerUITests.swift
|
|
|
|
// TuskerUITests
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/15/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
2019-12-30 20:59:49 +00:00
|
|
|
import Embassy
|
|
|
|
import Ambassador
|
2018-08-16 02:27:48 +00:00
|
|
|
|
|
|
|
class TuskerUITests: XCTestCase {
|
2019-12-30 20:59:49 +00:00
|
|
|
|
|
|
|
var eventLoop: EventLoop!
|
|
|
|
var router: Router!
|
|
|
|
var server: HTTPServer!
|
|
|
|
var eventLoopThreadCondition: NSCondition!
|
|
|
|
var eventLoopThread: Thread!
|
|
|
|
|
|
|
|
var app: XCUIApplication!
|
|
|
|
|
|
|
|
private func setupWebServer() {
|
|
|
|
eventLoop = try! SelectorEventLoop(selector: try! KqueueSelector())
|
|
|
|
router = Router()
|
|
|
|
server = DefaultHTTPServer(eventLoop: eventLoop, port: 8080, app: router.app)
|
|
|
|
router["/hello"] = JSONResponse(handler: { (_) in
|
|
|
|
return ["Hello", "World"]
|
|
|
|
})
|
|
|
|
try! server.start()
|
|
|
|
|
|
|
|
eventLoopThreadCondition = NSCondition()
|
|
|
|
eventLoopThread = Thread(block: {
|
|
|
|
self.eventLoop.runForever()
|
|
|
|
self.eventLoopThreadCondition.lock()
|
|
|
|
self.eventLoopThreadCondition.signal()
|
|
|
|
self.eventLoopThreadCondition.unlock()
|
|
|
|
})
|
|
|
|
eventLoopThread.start()
|
|
|
|
}
|
|
|
|
|
2018-08-16 02:27:48 +00:00
|
|
|
override func setUp() {
|
2019-12-30 20:59:49 +00:00
|
|
|
setupWebServer()
|
|
|
|
|
2018-08-16 02:27:48 +00:00
|
|
|
continueAfterFailure = false
|
2019-12-30 20:59:49 +00:00
|
|
|
app = XCUIApplication()
|
|
|
|
app.launchEnvironment["UI_TESTING"] = "true"
|
2018-08-16 02:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDown() {
|
2019-12-30 20:59:49 +00:00
|
|
|
server.stopAndWait()
|
|
|
|
eventLoopThreadCondition.lock()
|
|
|
|
eventLoop.stop()
|
|
|
|
while eventLoop.running {
|
|
|
|
if !eventLoopThreadCondition.wait(until: Date(timeIntervalSinceNow: 10)) {
|
|
|
|
fatalError("Join eventLoopThread timeout")
|
|
|
|
}
|
|
|
|
}
|
2018-08-16 02:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|