Add unit test to check thread safety.

This commit is contained in:
Benjamin Scholtysik (Reimold)
2017-10-18 13:31:27 -07:00
parent 2e5b212a43
commit 8761aebd5e

View File

@@ -120,4 +120,24 @@
XCTAssertEqual(strcmp(BITTelemetryEventBuffer,""), 0);
}
- (void) testBITEventBufferThreadSafety {
int count = 1000;
XCTestExpectation *expectation1 = [[XCTestExpectation alloc] initWithDescription:@"append"];
XCTestExpectation *expectation2 = [[XCTestExpectation alloc] initWithDescription:@"reset"];
dispatch_async(dispatch_queue_create("queue1", DISPATCH_QUEUE_SERIAL), ^{
for(int i = 0; i < count; i++) {
bit_appendStringToEventBuffer([NSString stringWithFormat:@"%d", i], &BITTelemetryEventBuffer);
}
[expectation1 fulfill];
});
dispatch_async(dispatch_queue_create("queue2", DISPATCH_QUEUE_SERIAL), ^{
for(int i = 0; i < count; i++) {
bit_resetEventBuffer(&BITTelemetryEventBuffer);
}
[expectation2 fulfill];
});
[self waitForExpectations:@[expectation1, expectation2] timeout: 10];
XCTAssertTrue(true);
}
@end