aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec/Tests/GPBConcurrencyTests.m
diff options
context:
space:
mode:
Diffstat (limited to 'objectivec/Tests/GPBConcurrencyTests.m')
-rw-r--r--objectivec/Tests/GPBConcurrencyTests.m48
1 files changed, 48 insertions, 0 deletions
diff --git a/objectivec/Tests/GPBConcurrencyTests.m b/objectivec/Tests/GPBConcurrencyTests.m
index 3749fc34..e500ad77 100644
--- a/objectivec/Tests/GPBConcurrencyTests.m
+++ b/objectivec/Tests/GPBConcurrencyTests.m
@@ -31,10 +31,16 @@
#import "GPBTestUtilities.h"
#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
static const int kNumThreads = 100;
static const int kNumMessages = 100;
+// NOTE: Most of these tests don't "fail" in the sense that the XCTAsserts
+// trip. Rather, the asserts simply exercise the apis, and if there is
+// a concurancy issue, the NSAsserts in the runtime code fire and/or the
+// code just crashes outright.
+
@interface ConcurrencyTests : GPBTestCase
@end
@@ -132,6 +138,48 @@ static const int kNumMessages = 100;
}
}
+- (void)readInt32Int32Map:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetInt32Int32MapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readInt32Int32Map:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+}
+
+- (void)readStringStringMap:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetStringStringMapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readStringStringMap:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+}
+
- (void)readOptionalForeignMessageExtension:(NSArray *)messages {
for (int i = 0; i < 10; i++) {
for (TestAllExtensions *message in messages) {