IOSAD-157 Check sync loop on start/shoutdown IOSAD-157
authorDirk Zimmermann <dz@pep.security>
Mon, 18 Nov 2019 15:54:57 +0100
branchIOSAD-157
changeset 134341c3edccf19d
parent 1342 dcaa25a3fd80
child 1344 748e3ffd7804
IOSAD-157 Check sync loop on start/shoutdown
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Mon Nov 18 15:54:57 2019 +0100
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Mon Nov 18 15:54:57 2019 +0100
     1.3 @@ -41,7 +41,7 @@
     1.4  
     1.5  - (void)tearDown
     1.6  {
     1.7 -    [self shutdownSync];
     1.8 +    [self shutdownSyncCheckIfRunning:NO];
     1.9      [self pEpCleanUp];
    1.10      [super tearDown];
    1.11  }
    1.12 @@ -1316,7 +1316,10 @@
    1.13      XCTAssertTrue([session leaveDeviceGroup:&error]);
    1.14      XCTAssertNil(error);
    1.15  
    1.16 -    [self shutdownSync];
    1.17 +    // leaving a device group should disable sync
    1.18 +    XCTAssertFalse(self.sync.isRunning);
    1.19 +
    1.20 +    [self shutdownSyncCheckIfRunning:NO];
    1.21  }
    1.22  
    1.23  #pragma mark - enable/disable sync
    1.24 @@ -1499,7 +1502,7 @@
    1.25      XCTAssertNotNil(decryptedNewBeacon);
    1.26      XCTAssertNil(error);
    1.27  
    1.28 -    [self shutdownSync];
    1.29 +    [self shutdownSyncCheckIfRunning:YES];
    1.30  }
    1.31  
    1.32  #pragma mark - Helpers
    1.33 @@ -1514,6 +1517,7 @@
    1.34                              userID:@"me-myself-and-i"
    1.35                              userName:@"pEp Me"
    1.36                              isOwn:YES];
    1.37 +
    1.38      NSError *error = nil;
    1.39      XCTAssertTrue([session mySelf:identMe error:&error]);
    1.40      XCTAssertNil(error);
    1.41 @@ -1530,7 +1534,7 @@
    1.42      XCTAssertNotNil(self.sendMessageDelegate.lastMessage);
    1.43  
    1.44      XCTAssertEqual(self.sendMessageDelegate.messages.count, 1);
    1.45 -    [self shutdownSync];
    1.46 +    [self shutdownSyncCheckIfRunning:YES];
    1.47  }
    1.48  
    1.49  - (void)startSync
    1.50 @@ -1542,11 +1546,23 @@
    1.51                   initWithSendMessageDelegate:self.sendMessageDelegate
    1.52                   notifyHandshakeDelegate:self.notifyHandshakeDelegate];
    1.53      [self.sync startup];
    1.54 +
    1.55 +    XCTKVOExpectation *expHaveStartedSync = [[XCTKVOExpectation alloc]
    1.56 +                                             initWithKeyPath:@"isRunning"
    1.57 +                                             object:self.sync
    1.58 +                                             expectedValue: [NSNumber numberWithBool:YES]];
    1.59 +    [self waitForExpectations:@[expHaveStartedSync] timeout:PEPTestInternalSyncTimeout];
    1.60 +
    1.61 +    XCTAssertTrue(self.sync.isRunning);
    1.62  }
    1.63  
    1.64 -- (void)shutdownSync
    1.65 +- (void)shutdownSyncCheckIfRunning:(BOOL)checkIfRunning
    1.66  {
    1.67 +    if (checkIfRunning) {
    1.68 +        XCTAssertTrue(self.sync.isRunning);
    1.69 +    }
    1.70      [self.sync shutdown];
    1.71 +    XCTAssertFalse(self.sync.isRunning);
    1.72  }
    1.73  
    1.74  - (NSNumber * _Nullable)testOutgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage