IOSAD-172 Can specify clean up timeout

IOSAD-172
Dirk Zimmermann 2 years ago
parent d21e85c0b7
commit 55baa3078e
  1. 7
      pEpObjCAdapter/PEPPassphraseCache.m
  2. 3
      pEpObjCAdapter/PEPPassphraseCacheInternal.h
  3. 6
      pEpObjCTests/PEPPassphraseCacheTest.m

@ -14,7 +14,7 @@
static NSUInteger s_maxNumberOfPassphrases = 20;
static NSTimeInterval s_defaultTimeoutInSeconds = 10 * 60;
static NSTimeInterval s_defaultRemoveStalePassphrasesTimeout = 60;
static NSTimeInterval s_defaultRemoveStalePassphrasesInterval = 60;
@interface PEPPassphraseCache ()
@ -27,6 +27,7 @@ static NSTimeInterval s_defaultRemoveStalePassphrasesTimeout = 60;
/// Internal constructor (for now).
- (instancetype)initWithTimeout:(NSTimeInterval)timeout
removeStalePassphrasesInterval:(NSTimeInterval)removeStalePassphrasesInterval
{
self = [super init];
if (self) {
@ -40,7 +41,9 @@ static NSTimeInterval s_defaultRemoveStalePassphrasesTimeout = 60;
/// Public constructor with default values.
- (instancetype)init
{
return [self initWithTimeout:s_defaultTimeoutInSeconds];
return [self
initWithTimeout:s_defaultTimeoutInSeconds
removeStalePassphrasesInterval:s_defaultRemoveStalePassphrasesInterval];
}
- (void)addPassphrase:(NSString *)passphrase

@ -12,7 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface PEPPassphraseCache (internal)
- (instancetype)initWithTimeout:(NSTimeInterval)timeout;
- (instancetype)initWithTimeout:(NSTimeInterval)timeout
removeStalePassphrasesInterval:(NSTimeInterval)removeStalePassphrasesInterval;
@end

@ -90,7 +90,9 @@
- (void)testTimeout
{
NSTimeInterval timeout = 0.5;
PEPPassphraseCache *ownCache = [[PEPPassphraseCache alloc] initWithTimeout:timeout];
PEPPassphraseCache *ownCache = [[PEPPassphraseCache alloc]
initWithTimeout:timeout
removeStalePassphrasesInterval:timeout];
NSString *ownPassphrase = @"blah";
[ownCache addPassphrase:ownPassphrase];
@ -98,7 +100,7 @@
NSArray *expectedBefore = @[@"", ownPassphrase];
XCTAssertEqualObjects(ownCache.passphrases, expectedBefore);
[NSThread sleepForTimeInterval:timeout];
[NSThread sleepForTimeInterval:3*timeout];
XCTAssertEqualObjects(ownCache.passphrases, @[@""]);
}

Loading…
Cancel
Save