-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove "context saved" expectation from CoreDataStack mocks #18485
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,6 @@ @implementation ContextManagerMock | |
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator; | ||
@synthesize mainContext = _mainContext; | ||
@synthesize managedObjectModel = _managedObjectModel; | ||
@synthesize requiresTestExpectation = _requiresTestExpectation; | ||
@synthesize testExpectation = _testExpectation; | ||
|
||
- (instancetype)init | ||
{ | ||
|
@@ -23,7 +21,6 @@ - (instancetype)init | |
// Override the shared ContextManager | ||
[ContextManager internalSharedInstance]; | ||
[ContextManager overrideSharedInstance:self]; | ||
_requiresTestExpectation = YES; | ||
} | ||
|
||
return self; | ||
|
@@ -79,40 +76,13 @@ - (NSManagedObjectContext *)mainContext | |
return _mainContext; | ||
} | ||
|
||
- (void)saveContext:(NSManagedObjectContext *)context | ||
{ | ||
[self saveContext:context withCompletionBlock:^{ | ||
if (self.testExpectation) { | ||
[self.testExpectation fulfill]; | ||
self.testExpectation = nil; | ||
} else if (self.requiresTestExpectation) { | ||
NSLog(@"No test expectation present for context save"); | ||
} | ||
}]; | ||
} | ||
|
||
- (void)saveContextAndWait:(NSManagedObjectContext *)context | ||
{ | ||
[super saveContextAndWait:context]; | ||
if (self.testExpectation) { | ||
[self.testExpectation fulfill]; | ||
self.testExpectation = nil; | ||
} else if (self.requiresTestExpectation) { | ||
NSLog(@"No test expectation present for context save"); | ||
} | ||
} | ||
|
||
- (void)saveContext:(NSManagedObjectContext *)context withCompletionBlock:(void (^)(void))completionBlock | ||
{ | ||
[super saveContext:context withCompletionBlock:^{ | ||
if (self.testExpectation) { | ||
[self.testExpectation fulfill]; | ||
self.testExpectation = nil; | ||
} else if (self.requiresTestExpectation) { | ||
NSLog(@"No test expectation present for context save"); | ||
} | ||
completionBlock(); | ||
}]; | ||
// FIXME: Remove this method to use superclass one instead | ||
// This log magically resolves a deadlock in | ||
// `ZDashboardCardTests.testShouldNotShowQuickStartIfDefaultSectionIsSiteMenu` | ||
NSLog(@"Context save completed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still trying to figure out cause of this deadlock 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what is worth, I can see the deadlock without this line on my end, too. The test you mention just sits there with a spinner next to it in the test navigator. |
||
} | ||
|
||
- (NSURL *)storeURL | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this PR replaces all the
waitForExpectations(timeout:, handler:)
withwait(for:, timeout:)
.What's your rationale for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this expectation was the only expectation created within this test method. This change is just making that explicit - test method is waiting for main context to be saved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. One could argue that using
waitForExpectations(timeout:, handler:)
would make for smaller diffs, because if we add new expectations that method will automatically wait for them.But, I'm with you on the value of explicitly stating which expectation we're waiting for. 👍