Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Objective-C/Tests/CBLTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ extern const NSTimeInterval kExpTimeout;
*/
- (XCTestExpectation*) allowOverfillExpectationWithDescription:(NSString *)description;

/** A utility function for waiting for the condition or timeout, spinning the run loop without blocking. */
- (BOOL) waitWithTimeout: (NSTimeInterval)timeout
interval: (NSTimeInterval)interval
until: (BOOL (^)(void))condition;

@end

NS_ASSUME_NONNULL_END
33 changes: 19 additions & 14 deletions Objective-C/Tests/CBLTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ @implementation CBLTestCase

@synthesize db=_db, otherDB=_otherDB, disableObjectLeakCheck=_disableObjectLeakCheck;

// TODO: Remove https://issues.couchbase.com/browse/CBL-3206
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

- (XCTestExpectation*) allowOverfillExpectationWithDescription:(NSString *)description {
XCTestExpectation* e = [super expectationWithDescription: description];
e.assertForOverFulfill = false;
Expand Down Expand Up @@ -75,15 +71,12 @@ - (void) tearDown {

if (!_disableObjectLeakCheck) {
// Wait a little while for objects to be cleaned up:
int leaks = 0;
for (int i = 0; i < 20; i++) {
leaks = c4_getObjectCount() - _c4ObjectCount;
if (leaks == 0)
break;
else
[NSThread sleepForTimeInterval: 0.1];
}
if (leaks) {
__block int leaks = 0;
BOOL success = [self waitWithTimeout: 8 interval: 0.5 until: ^BOOL{
leaks = c4_getObjectCount() - self->_c4ObjectCount;
return leaks == 0;
}];
if (!success) {
fprintf(stderr, "**** LITECORE OBJECTS STILL NOT FREED: ****\n");
c4_dumpInstances();
XCTFail("%d LiteCore objects have not been freed (see above)", leaks);
Expand Down Expand Up @@ -483,6 +476,18 @@ - (NSString*) getRickAndMortyJSON {
return [self stringFromResource: @"rick_morty" ofType: @"json"];
}

#pragma clang diagnostic pop
- (BOOL) waitWithTimeout: (NSTimeInterval)timeout
interval: (NSTimeInterval)interval
until: (BOOL (^)(void))condition {
NSDate *deadline = [NSDate dateWithTimeIntervalSinceNow: timeout];
while ([deadline timeIntervalSinceNow] > 0) {
if (condition()) {
return YES;
}
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: [NSDate dateWithTimeIntervalSinceNow: interval]];
}
return condition();
}

@end
9 changes: 7 additions & 2 deletions Objective-C/Tests/MultipeerReplicatorTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#define kTestMaxIdentity 10
#define kTestIdentityCommonName @"CBLMultipeerReplTest"

// Disable as cannot be run on the build VM (Got POSIX Error 50, Network is down)
#define kDisableMultipeerTests YES

typedef NSMutableDictionary<CBLPeerID*, CBLPeerReplicatorStatus*> CBLPeerReplicatorStatusMap;

typedef CBLDocument * _Nullable (^MultipeerConflictResolverBlock)(CBLPeerID*, CBLConflict*);
Expand Down Expand Up @@ -67,6 +70,9 @@ - (void) setUp {

XCTSkipUnless(self.isExecutionAllowed);

// Disabled by testConfigurationValidation, ensure to re-enable the leak check:
self.disableObjectLeakCheck = NO;

[self cleanupIdentities];
[self openOtherDB];

Expand All @@ -90,8 +96,7 @@ - (BOOL) isExecutionAllowed {
// See FAQ-12 : https://developer.apple.com/forums/thread/663858)
return NO;
#else
// Disable as cannot be run on the build VM (Got POSIX Error 50, Network is down)
return self.keyChainAccessAllowed && false;
return kDisableMultipeerTests ? NO : self.keyChainAccessAllowed;
#endif
}

Expand Down
6 changes: 4 additions & 2 deletions Swift/Tests/MultipeerReplicatorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class MultipeerReplicatorTest: CBLTestCase {
}
}

// Disable as cannot be run on the build VM (Got POSIX Error 50, Network is down)
let kDisableMultipeerReplicatorTest = true

let kTestKeyUsages: KeyUsages = [.clientAuth, .serverAuth]

let kTestPeerGroupID = "CBLMultipeerReplTestGroup"
Expand All @@ -59,8 +62,7 @@ class MultipeerReplicatorTest: CBLTestCase {
// See FAQ-12: https://developer.apple.com/forums/thread/663858
return false
#else
// Disable as cannot be run on the build VM (Got POSIX Error 50, Network is down)
return keyChainAccessAllowed && false
return kDisableMultipeerReplicatorTest ? false : keyChainAccessAllowed;
#endif
}

Expand Down
Loading