Skip to content
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

[WIP] Fix strong reference cycles for STPRedirectContext, Improve tests #804

Closed
wants to merge 2 commits into from

Conversation

joeydong-stripe
Copy link
Contributor

@joeydong-stripe joeydong-stripe commented Sep 25, 2017

Fixing test failures found in: #802

Summary

I think the STPRedirectContext was failing tests quietly in our previous Xcode 8, iOS 10.x testing but shows up when we enable the other Xcode / iOS versions.

  1. The first problem is some of the tests were intended to never call the unsubscribeFromUrlAndForegroundNotifications. In particular, because the STPURLCallbackHandler held a strong reference, the STPRedirectContext<STPURLCallbackListener> ended up staying alive between tests leading to unexpected results.

  2. The second problem is the startRedirectFlowFromViewController was implicitly holding a strong reference to itself in its completion block. Reproducing this is similar to the first problem, either put a breakpoint in dealloc and make sure it's called after every test, or send a valid url scheme to the STPURLCallbackHandler and see if any listener picks up.

  3. Finally, we needed to adjust the test cases so that they're compatible with all tested iOS versions

I took a broader stroke in the second commit because I was often getting lost/confused when trying to understand the implementation of STPRedirectContext. I think some key method renaming is sufficient to solve that but definitely want to avoid introducing new bugs.

The tests are still really tricky to maintain but the implementation itself is good so a refactoring just to simplify tests is probably a bad idea right now.

TODO: Update documentation, add CHANGELOG and MIGRATING entry to warn about holding a strong reference to STPRedirectContext which was not needed before

@joeydong-stripe joeydong-stripe force-pushed the joey/fixRedirectContextReference branch from 12d38cc to d20a2b9 Compare September 26, 2017 22:03
object:nil];
[[STPURLCallbackHandler shared] registerListener:self
forURL:self.source.redirect.returnURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationWillEnterForegroundNotification) name:UIApplicationWillEnterForegroundNotification object:nil];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you go through and remove the line breaks from like, every method call in all these files? I find it much harder to read like this.

@@ -32,7 +32,7 @@ + (BOOL)handleStripeURLCallbackWithURL:(NSURL *)url FAUXPAS_IGNORED_ON_LINE(Unus

@interface STPURLCallback : NSObject
@property (nonatomic) NSURLComponents *urlComponents;
@property (nonatomic) id<STPURLCallbackListener> listener;
@property (nonatomic, weak) id<STPURLCallbackListener> listener;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it potentially actually better to just leave this as it was and let the context retain itself for the duration of the redirect or until a cancel occurs? Or do you think that behavior is too unexpected.

@bdorfman-stripe
Copy link
Contributor

Note: The retain cycle issues have been fixed on their own in #846

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants