Improved test for parallel sessions
authorDirk Zimmermann <dirk@pep-project.org>
Fri, 04 Mar 2016 12:30:12 +0100
changeset 99d576c77bf81b
parent 98 62aeaec141fd
child 100 c2f33f275d55
Improved test for parallel sessions
iOSTests/iOSTests.m
     1.1 --- a/iOSTests/iOSTests.m	Fri Mar 04 11:12:46 2016 +0100
     1.2 +++ b/iOSTests/iOSTests.m	Fri Mar 04 12:30:12 2016 +0100
     1.3 @@ -787,11 +787,11 @@
     1.4      [self pEpCleanUp];
     1.5  }
     1.6  
     1.7 -- (void)doSomeWorkOnSession:(PEPSession *)session
     1.8 +- (void)doSomeWorkOnSession:(PEPSession *)session count:(NSInteger)count
     1.9  {
    1.10 -    NSMutableDictionary *me = @{ kPepAddress: @"me@dontcare.me",
    1.11 -                                 kPepUserID: @"me",
    1.12 -                                 kPepUsername: @"me" }.mutableCopy;
    1.13 +    NSMutableDictionary *me = @{ kPepAddress: [NSString stringWithFormat:@"me%d@dontcare.me", count],
    1.14 +                                 kPepUserID: [NSString stringWithFormat:@"me%d", count],
    1.15 +                                 kPepUsername: [NSString stringWithFormat:@"me%d", count] }.mutableCopy;
    1.16      [session mySelf:me];
    1.17      XCTAssertNotNil(me[kPepFingerprint]);
    1.18  }
    1.19 @@ -800,22 +800,24 @@
    1.20  {
    1.21      [PEPiOSAdapter setupTrustWordsDB:[NSBundle bundleForClass:[self class]]];
    1.22  
    1.23 +    // Currently, the first session use MUST be on the main thread
    1.24      PEPSession *session = [PEPSession session];
    1.25 +    [self doSomeWorkOnSession:session count:0];
    1.26  
    1.27      dispatch_group_t group = dispatch_group_create();
    1.28      dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_CONCURRENT);
    1.29  
    1.30 -    for (int i = 0; i < 3; ++i) {
    1.31 +    for (int i = 1; i < 3; ++i) {
    1.32          dispatch_group_async(group, queue, ^{
    1.33              PEPSession *innerSession = [PEPSession session];
    1.34 -            [self doSomeWorkOnSession:innerSession];
    1.35 +            [self doSomeWorkOnSession:innerSession count:i];
    1.36          });
    1.37      }
    1.38  
    1.39 -    [self doSomeWorkOnSession:session];
    1.40 -
    1.41      long result = dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
    1.42      XCTAssertEqual(result, 0);
    1.43 +
    1.44 +    [self pEpCleanUp];
    1.45  }
    1.46  
    1.47  @end