diff --git a/Support/HockeySDKTests/BITChannelTests.m b/Support/HockeySDKTests/BITChannelTests.m index 955da6f7fa..fc437dea82 100644 --- a/Support/HockeySDKTests/BITChannelTests.m +++ b/Support/HockeySDKTests/BITChannelTests.m @@ -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