A WIP iOS app for Mastodon and Pleroma.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TuskerUITests.swift 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // TuskerUITests.swift
  3. // TuskerUITests
  4. //
  5. // Created by Shadowfacts on 8/15/18.
  6. // Copyright © 2018 Shadowfacts. All rights reserved.
  7. //
  8. import XCTest
  9. import Embassy
  10. import Ambassador
  11. class TuskerUITests: XCTestCase {
  12. var eventLoop: EventLoop!
  13. var router: Router!
  14. var server: HTTPServer!
  15. var eventLoopThreadCondition: NSCondition!
  16. var eventLoopThread: Thread!
  17. var app: XCUIApplication!
  18. private func setupWebServer() {
  19. eventLoop = try! SelectorEventLoop(selector: try! KqueueSelector())
  20. router = Router()
  21. server = DefaultHTTPServer(eventLoop: eventLoop, port: 8080, app: router.app)
  22. router["/hello"] = JSONResponse(handler: { (_) in
  23. return ["Hello", "World"]
  24. })
  25. try! server.start()
  26. eventLoopThreadCondition = NSCondition()
  27. eventLoopThread = Thread(block: {
  28. self.eventLoop.runForever()
  29. self.eventLoopThreadCondition.lock()
  30. self.eventLoopThreadCondition.signal()
  31. self.eventLoopThreadCondition.unlock()
  32. })
  33. eventLoopThread.start()
  34. }
  35. override func setUp() {
  36. setupWebServer()
  37. continueAfterFailure = false
  38. app = XCUIApplication()
  39. app.launchEnvironment["UI_TESTING"] = "true"
  40. }
  41. override func tearDown() {
  42. server.stopAndWait()
  43. eventLoopThreadCondition.lock()
  44. eventLoop.stop()
  45. while eventLoop.running {
  46. if !eventLoopThreadCondition.wait(until: Date(timeIntervalSinceNow: 10)) {
  47. fatalError("Join eventLoopThread timeout")
  48. }
  49. }
  50. }
  51. }