From 310aeb6d6c9fc9f4103322812752359890530fdc Mon Sep 17 00:00:00 2001 From: Michael Tyson Date: Thu, 16 Jun 2016 20:27:55 +1000 Subject: [PATCH] Added AEMainThreadEndpoint stress test --- Tests/AECrossThreadMessagingTests.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Tests/AECrossThreadMessagingTests.m b/Tests/AECrossThreadMessagingTests.m index b456db4..83e5250 100644 --- a/Tests/AECrossThreadMessagingTests.m +++ b/Tests/AECrossThreadMessagingTests.m @@ -62,6 +62,24 @@ - (void)testMainThreadEndpointMessaging { XCTAssertNil(weakEndpoint); } +- (void)testMainThreadEndpointStressTest { + __block int counter = 0; + AEMainThreadEndpoint * endpoint = [[AEMainThreadEndpoint alloc] initWithHandler:^(const void *data, size_t length) { + counter++; + }]; + + dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ + for ( int i=0; i<100; i++) { + AEMainThreadEndpointSend(endpoint, NULL, 0); + usleep(100); + } + }); + + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; + + XCTAssertEqual(counter, 100); +} + - (void)testAudioThreadEndpointMessaging { NSMutableArray * messages = [NSMutableArray array]; AEAudioThreadEndpoint * endpoint = [[AEAudioThreadEndpoint alloc] initWithHandler:^(const void *data, size_t length) {