title: How to trigger failed test on timeout with waitForExpectations()?
body: <p>I've recreated the example from here: <a href="http://www.mokacoding.com/blog/testing-callbacks-in-swift-with-xctest/" rel="nofollow noreferrer">http://www.mokacoding.com/blog/testing-callbacks-in-swift-with-xctest/</a>.</p>
  
  <p>I want to test for a timeout using <code>waitForExpectations()</code>. This should mimic a long running process that has timed out. To do this, I've set a <code>sleep()</code> command in the called function that is longer than the timeout in <code>waitForExpectations()</code>. </p>
  
  <p>However, the <code>sleep()</code> doesn't have any effect. The test always passes. I've tried putting <code>sleep()</code> before <code>completion(true)</code> as well but that doesn't change the outcome (i.e., passed test). </p>
  
  <p>Any ideas what I'm doing run to trigger a test failure on timeout?</p>
  
  <pre><code>class SomeService {
      func doSomethingAsync(completion: (_ success: Bool) -&gt; ()) {
          completion(true)
          sleep(5)
      }
  }
  </code></pre>
  
  <p>In test class</p>
  
  <pre><code>let service = SomeService()
  service.doSomethingAsync { (success) in
      XCTAssertTrue(success, "assert is true")
      expect.fulfill()
  }
  
  waitForExpectations(timeout: 3) { (error) in
      if let error = error {
          XCTFail("timeout errored: \(error)")
      }
  }
  </code></pre>