mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Swift
		
	
| 
											6 years ago
										 | import XCTest | ||
|  | 
 | ||
|  | extension XCTestCase { | ||
|  | 
 | ||
| 
											6 years ago
										 |     /// A helper for asynchronous testing. | ||
|  |     /// | ||
|  |     /// Usage example: | ||
|  |     /// | ||
|  |     /// ``` | ||
|  |     /// func testSomething() { | ||
|  |     ///     doAsyncThings() | ||
|  |     ///     eventually { | ||
|  |     ///         /* XCTAssert goes here... */ | ||
|  |     ///     } | ||
|  |     /// } | ||
|  |     /// ``` | ||
|  |     /// | ||
|  |     /// The provided closure won't execute until `timeout` seconds have passed. Pass | ||
|  |     /// in a timeout long enough for your asynchronous process to finish if it's | ||
| 
											6 years ago
										 |     /// expected to take more than the default 0.1 second. | ||
|  |     /// | ||
|  |     /// - Parameters: | ||
| 
											6 years ago
										 |     ///   - timeout: number of seconds to wait before executing `closure`. | ||
|  |     ///   - closure: a closure to execute when `timeout` seconds have passed. | ||
| 
											6 years ago
										 |     /// | ||
|  |     /// - Note: `timeout` must be less than 60 seconds. | ||
| 
											6 years ago
										 |     func eventually(timeout: TimeInterval = 0.1, closure: @escaping () -> Void) { | ||
| 
											6 years ago
										 |         assert(timeout < 60) | ||
| 
											6 years ago
										 |         let expectation = self.expectation(description: "") | ||
|  |         expectation.fulfillAfter(timeout) | ||
|  |         self.waitForExpectations(timeout: 60) { _ in | ||
|  |             closure() | ||
|  |         } | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | extension XCTestExpectation { | ||
|  | 
 | ||
|  |     /// Call `fulfill()` after some time. | ||
|  |     /// | ||
| 
											6 years ago
										 |     /// - Parameter time: number of seconds after which `fulfill()` will be called. | ||
| 
											6 years ago
										 |     func fulfillAfter(_ time: TimeInterval) { | ||
|  |         DispatchQueue.main.asyncAfter(deadline: .now() + time) { | ||
|  |             self.fulfill() | ||
|  |         } | ||
|  |     } | ||
|  | } |