From 8761aebd5e28a1e0c3dcedff09b41fec92737ebb Mon Sep 17 00:00:00 2001 From: "Benjamin Scholtysik (Reimold)" Date: Wed, 18 Oct 2017 13:31:27 -0700 Subject: [PATCH] Add unit test to check thread safety. --- Support/HockeySDKTests/BITChannelTests.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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