Skip to content
Snippets Groups Projects
Commit a8d40b56 authored by Muxi Yan's avatar Muxi Yan
Browse files

Asynchronously wait for tests

parent 49b7f834
Branches
Tags
No related merge requests found
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#import <RxLibrary/GRXWriteable.h> #import <RxLibrary/GRXWriteable.h>
#import <RxLibrary/GRXWriter.h> #import <RxLibrary/GRXWriter.h>
#define TEST_TIMEOUT 1
// A mock of a GRXSingleValueHandler block that can be queried for how many times it was called and // A mock of a GRXSingleValueHandler block that can be queried for how many times it was called and
// what were the last values passed to it. // what were the last values passed to it.
// //
...@@ -155,9 +157,14 @@ ...@@ -155,9 +157,14 @@
#pragma mark BufferedPipe #pragma mark BufferedPipe
- (void)testBufferedPipePropagatesValue { - (void)testBufferedPipePropagatesValue {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Response received"];
// Given: // Given:
CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler]; CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block]; id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
handler.block(value, errorOrNil);
[expectation fulfill];
}];
id anyValue = @7; id anyValue = @7;
// If: // If:
...@@ -166,13 +173,12 @@ ...@@ -166,13 +173,12 @@
[pipe writeValue:anyValue]; [pipe writeValue:anyValue];
[pipe writesFinishedWithError:nil]; [pipe writesFinishedWithError:nil];
// Wait buffered pipe to be flushed.
sleep(1);
// Then: // Then:
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
XCTAssertEqual(handler.timesCalled, 1); XCTAssertEqual(handler.timesCalled, 1);
XCTAssertEqualObjects(handler.value, anyValue); XCTAssertEqualObjects(handler.value, anyValue);
XCTAssertEqualObjects(handler.errorOrNil, nil); XCTAssertEqualObjects(handler.errorOrNil, nil);
} }
- (void)testBufferedPipePropagatesError { - (void)testBufferedPipePropagatesError {
...@@ -193,9 +199,13 @@ ...@@ -193,9 +199,13 @@
} }
- (void)testBufferedPipeFinishWriteWhilePaused { - (void)testBufferedPipeFinishWriteWhilePaused {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Response received"];
// Given: // Given:
CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler]; CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block]; id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
handler.block(value, errorOrNil);
[expectation fulfill];
}];
id anyValue = @7; id anyValue = @7;
// If: // If:
...@@ -205,9 +215,9 @@ ...@@ -205,9 +215,9 @@
[pipe writesFinishedWithError:nil]; [pipe writesFinishedWithError:nil];
// then start the writeable // then start the writeable
[pipe startWithWriteable:writeable]; [pipe startWithWriteable:writeable];
sleep(1);
// Then: // Then:
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
XCTAssertEqual(handler.timesCalled, 1); XCTAssertEqual(handler.timesCalled, 1);
XCTAssertEqualObjects(handler.value, anyValue); XCTAssertEqualObjects(handler.value, anyValue);
XCTAssertEqualObjects(handler.errorOrNil, nil); XCTAssertEqualObjects(handler.errorOrNil, nil);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment