[ios, macos] Short-circuit packs test

If the packs property is already populated, there’s no need to wait for a change notification.
This commit is contained in:
Minh Nguyễn
2016-08-21 22:38:36 -07:00
committed by John Firebaugh
parent 6a2ce352d1
commit 2c8e030550

View File

@@ -13,12 +13,15 @@
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) {
XCTestExpectation *expectation = [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) {
NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue];
return changeKind = NSKeyValueChangeSetting;
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
if ([MGLOfflineStorage sharedOfflineStorage].packs) {
[expectation fulfill];
} else {
[self waitForExpectationsWithTimeout:1 handler:nil];
}
XCTAssertNotNil([MGLOfflineStorage sharedOfflineStorage].packs, @"Shared offline storage object should have a non-nil collection of packs by this point.");
});