-
Notifications
You must be signed in to change notification settings - Fork 26
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
Test suite: avoid calling the fulfill
after the wait context has ended
#303
Conversation
Doesn't assigning a freshly allocated object to a weak variable just deallocate the object right away? From a quick test: 10> func test() {
11. weak var x = NSString(string: "not nil")
12. print(x)
13. }
14> test()
nil |
Yes, that's my point but it will wait because of the |
Can I merge? |
7f4a1f4
to
0fe7e92
Compare
0fe7e92
to
43fde2b
Compare
I mean that, unless I'm mistaken, the |
Yes, correct. In your example the instance has no strong reference but when you create an expectation
Thus there are two references to it. I don't know if one of them is a strong but I tested it and it's working as expected: - (void)testSubscribeToName {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testSubscribeToName"];
NSString *channelName = @"channel";
[ARTTestUtil testRealtime:^(ARTRealtime *realtime) {
NSLog(@"------- %@", expectation);
_realtime = realtime;
ARTRealtimeChannel *channel = [realtime.channels get:channelName];
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
NSLog(@"------- %@", expectation);
}
|
Ah, OK, of course, |
Test suite: avoid calling the `fulfill` after the wait context has ended
I declared each expectation variable as
__weak
to avoid API violations. The expectation will be released when the timeout expires. So if the task takes longer than the timeout, the expectation variable will be nil when the task completion handler is called. Thus thefulfill
method will be called on nil, doing nothing.