         let expectation = expectationWithDescription("Expected on main queue")
         var calledStuffAfterSinceAsync = false
         Async.main {
-            XCTAssertEqual(qos_class_self(), qos_class_main(), "On \(qos_class_self().description) (expected \(qos_class_main().description))")
+            #if (arch(i386) || arch(x86_64)) && (os(iOS) || os(tvOS)) // Simulator
+                XCTAssert(NSThread.isMainThread(), "Should be on main thread (simulator)")
+            #else
+                XCTAssertEqual(qos_class_self(), qos_class_main(), "On \(qos_class_self().description) (expected \(qos_class_main().description))")
+            #endif
             XCTAssert(calledStuffAfterSinceAsync, "Should be async")
             expectation.fulfill()
         }
         calledStuffAfterSinceAsync = true
-        waitForExpectationsWithTimeout(1, handler: nil)
+        waitForExpectationsWithTimeout(timeMargin, handler: nil)
     }
 
     func testAsyncUserInteractive() {


            let timePassed = NSDate().timeIntervalSinceDate(date2)
            XCTAssert(timePassed >= lowerTimeDelay2, "Should wait \(timePassed) >= \(lowerTimeDelay2) seconds before firing")
            XCTAssert(timePassed < upperTimeDelay2, "Shouldn't wait \(timePassed), but <\(upperTimeDelay2) seconds before firing")
            XCTAssertEqual(qos_class_self(), QOS_CLASS_USER_INITIATED, "On \(qos_class_self().description) (expected \(QOS_CLASS_USER_INITIATED.description))")
            expectation.fulfill()
        }
        waitForExpectationsWithTimeout((timeDelay1 + timeDelay2) * 2, handler: nil)
    }

    func testAfterChainedUtility() {
        let expectation = expectationWithDescription("Expected after time")
        let date1 = NSDate()
        var date2 = NSDate()
        let timeDelay1 = 1.1
        let lowerTimeDelay1 = timeDelay1 - timeMargin
        let upperTimeDelay1 = timeDelay1 + timeMargin
        let timeDelay2 = 1.2
        let lowerTimeDelay2 = timeDelay2 - timeMargin
        let upperTimeDelay2 = timeDelay2 + timeMargin
        var id = 0
        Async.utility(after: timeDelay1) {
            XCTAssertEqual(++id, 1, "First after")


        let expectation = expectationWithDescription("Expected after time")
        let date = NSDate()
        let lowerTimeDelay = timeDelay - timeMargin
        let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeDelay * Double(NSEC_PER_SEC)))
        let queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)
        dispatch_after(time, queue, {
            let timePassed = NSDate().timeIntervalSinceDate(date)
            XCTAssert(timePassed >= lowerTimeDelay, "Should wait \(timePassed) >= \(lowerTimeDelay) seconds before firing")
            XCTAssertEqual(qos_class_self(), QOS_CLASS_BACKGROUND, "On \(qos_class_self().description) (expected \(QOS_CLASS_BACKGROUND.description))")
            expectation.fulfill()
        })
        waitForExpectationsWithTimeout(timeDelay + timeMargin, handler: nil)
    }

    func testAfterMain() {
        let expectation = expectationWithDescription("Expected after time")
        let date = NSDate()
        let lowerTimeDelay = timeDelay - timeMargin
        Async.main(after: timeDelay) {
            let timePassed = NSDate().timeIntervalSinceDate(date)
            XCTAssert(timePassed >= lowerTimeDelay, "Should wait \(timePassed) >= \(lowerTimeDelay) seconds before firing")
            XCTAssertEqual(qos_class_self(), qos_class_main(), "On main queue")
            expectation.fulfill()
        }
        waitForExpectationsWithTimeout(timeDelay + timeMargin, handler: nil)
    }

    func testAfterUserInteractive() {
        let expectation = expectationWithDescription("Expected after time")
        let date = NSDate()
        let lowerTimeDelay = timeDelay - timeMargin
        Async.userInteractive(after: timeDelay) {
            let timePassed = NSDate().timeIntervalSinceDate(date)
            XCTAssert(timePassed >= lowerTimeDelay, "Should wait \(timePassed) >= \(lowerTimeDelay) seconds before firing")
            XCTAssertEqual(qos_class_self(), QOS_CLASS_USER_INTERACTIVE, "On user interactive queue")
            expectation.fulfill()
        }
        waitForExpectationsWithTimeout(timeDelay + timeMargin, handler: nil)
    }

    func testAfterUserInitated() {
        let expectation = expectationWithDescription("Expected after time")
        let date = NSDate()
        let lowerTimeDelay = timeDelay - timeMargin
        Async.userInitiated(after: timeDelay) {
            let timePassed = NSDate().timeIntervalSinceDate(date)
            XCTAssert(timePassed >= lowerTimeDelay, "Should wait \(timePassed) >= \(lowerTimeDelay) seconds before firing")
            XCTAssertEqual(qos_class_self(), QOS_CLASS_USER_INITIATED, "On user initiated queue")
            expectation.fulfill()
        }
        waitForExpectationsWithTimeout(timeDelay + timeMargin, handler: nil)
    }

    func testAfterUtility() {
        let expectation = expectationWithDescription("Expected after time")
        let date = NSDate()
        let lowerTimeDelay = timeDelay - timeMargin
        Async.utility(after: timeDelay) {
            let timePassed = NSDate().timeIntervalSinceDate(date)
            XCTAssert(timePassed >= lowerTimeDelay, "Should wait \(timePassed) >= \(lowerTimeDelay) seconds before firing")
            XCTAssertEqual(qos_class_self(), QOS_CLASS_UTILITY, "On utility queue")
            expectation.fulfill()
        }
        waitForExpectationsWithTimeout(timeDelay + timeMargin, handler: nil)
    }

    func testAfterBackground() {
        let expectation = expectationWithDescription("Expected after time")
        let date = NSDate()
        let lowerTimeDelay = timeDelay - timeMargin
        Async.background(after: timeDelay) {
            let timePassed = NSDate().timeIntervalSinceDate(date)
            XCTAssert(timePassed >= lowerTimeDelay, "Should wait \(timePassed) >= \(lowerTimeDelay) seconds before firing")
            XCTAssertEqual(qos_class_self(), QOS_CLASS_BACKGROUND, "On background queue")
            expectation.fulfill()
        }
        waitForExpectationsWithTimeout(timeDelay + timeMargin, handler: nil)
    }

    func testAfterCustomQueue() {
        let expectation = expectationWithDescription("Expected after time")
        let date = NSDate()
        let timeDelay = 1.0
        let lowerTimeDelay = timeDelay - timeMargin
        let customQueue = dispatch_queue_create("CustomQueueLabel", DISPATCH_QUEUE_CONCURRENT)
        Async.customQueue(customQueue, after: timeDelay) {
            let timePassed = NSDate().timeIntervalSinceDate(date)
            XCTAssert(timePassed >= lowerTimeDelay, "Should wait \(timePassed) >= \(lowerTimeDelay) seconds before firing")
            expectation.fulfill()
        }
        waitForExpectationsWithTimeout(timeDelay + timeMargin, handler: nil)
    }

    func testAfterChainedMix() {
        let expectation = expectationWithDescription("Expected after time")
        let date1 = NSDate()
        var date2 = NSDate()
        let timeDelay1 = timeDelay
        let lowerTimeDelay1 = timeDelay1 - timeMargin
        let upperTimeDelay1 = timeDelay1 + timeMargin
        let timeDelay2 = timeDelay
        let lowerTimeDelay2 = timeDelay2 - timeMargin
        var id = 0
        Async.userInteractive(after: timeDelay1) {
            XCTAssertEqual(++id, 1, "First after")
