-
Notifications
You must be signed in to change notification settings - Fork 738
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
Add ability to pause/resume websocket without dumping subscriptions #1335
Conversation
bb51a2b
to
2465544
Compare
2465544
to
10c3524
Compare
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.
Overall looks légit
About omitting self, I just like less code and use
self` only where it is used.
/// Reconnects a paused web socket. | ||
/// | ||
/// - Parameter autoReconnect: `true` if you want the websocket to automatically reconnect if the connection drops. Defaults to true. | ||
public func resumeWebSocketConnection(autoReconnect: Bool = true) { |
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 think just reconnect
is fine? Aligning it with Starscream. But on other hand adding auto
can be more explicit. :P
} | ||
|
||
extension StarWarsSubscriptionTests: WebSocketTransportDelegate { | ||
|
||
func webSocketTransportDidConnect(_ webSocketTransport: WebSocketTransport) { | ||
self.connectionStartedExpectation?.fulfill() | ||
} | ||
|
||
func webSocketTransportDidReconnect(_ webSocketTransport: WebSocketTransport) { | ||
self.reconnectedExpectation?.fulfill() |
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.
self.reconnectedExpectation?.fulfill() | |
reconnectedExpectation?.fulfill() |
I don't know if there is a style guide, but I usually omit self
when it's not needed.
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.
There is not currently.
Personally, I find self
makes it much easier to disambiguate local vars from class vars when you're looking at things without syntax highlighting (ex, in Github). At some point I do want to make this more consistent throughout the codebase, but I'm gonna leave these for now.
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.
OK yep, being consistent is the key here, I agree!
} | ||
|
||
func webSocketTransport(_ webSocketTransport: WebSocketTransport, didDisconnectWithError error: Error?) { | ||
self.disconnectedExpectation?.fulfill() |
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.
self.disconnectedExpectation?.fulfill() | |
disconnectedExpectation?.fulfill() |
httpClient.perform(mutation: reviewMutation) { mutationResult in | ||
switch mutationResult { | ||
case .success: | ||
break |
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.
Hmm how about already here it can fulfill the expectation? Or I'm missing something.
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.
The expectation should be fulfilled and the wait should be ended no matter which case comes in, so that's why it's below the switch
statement
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 think XCTFail runs before I guess. Hmm ...
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.
Yep that's by design - we want that failure to occur before the wait ends.
self.waitForSubscriptionsToStart() | ||
sendReview() | ||
|
||
self.disconnectedExpectation = self.expectation(description: "Web socket disconnected") |
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.
self.disconnectedExpectation = self.expectation(description: "Web socket disconnected") | |
disconnectedExpectation = expectation(description: "Web socket disconnected") |
|
||
self.disconnectedExpectation = self.expectation(description: "Web socket disconnected") | ||
webSocketTransport.pauseWebSocketConnection() | ||
self.wait(for: [self.disconnectedExpectation!], timeout: 10) |
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.
self.wait(for: [self.disconnectedExpectation!], timeout: 10) | |
wait(for: [disconnectedExpectation!], timeout: 10) |
Do we need to specify exact expectation here?
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.
Yes since that's the only one we want to wait for
// This should not go through since the socket is paused | ||
sendReview() | ||
|
||
self.reconnectedExpectation = self.expectation(description: "Web socket reconnected") |
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.
self.reconnectedExpectation = self.expectation(description: "Web socket reconnected") | |
reconnectedExpectation = expectation(description: "Web socket reconnected") |
self.wait(for: [self.reconnectedExpectation!], timeout: 10) | ||
self.waitForSubscriptionsToStart() |
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.
self.wait(for: [self.reconnectedExpectation!], timeout: 10) | |
self.waitForSubscriptionsToStart() | |
wait(for: [reconnectedExpectation!], timeout: 10) | |
waitForSubscriptionsToStart() |
// Now that we've reconnected, this should go through to the same subscription. | ||
sendReview() | ||
|
||
self.wait(for: [subscriptionExpectation], timeout: 10) |
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.
self.wait(for: [subscriptionExpectation], timeout: 10) | |
wait(for: [subscriptionExpectation], timeout: 10) |
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.
Overall looks légit
About omitting self, I just like less code and use
self` only where it is used.
Co-authored-by: Kristaps Grinbergs <[email protected]>
At some point I'll have to make a real decision about |
Addresses #1333.
@fassko If you're around, I'd love your advice on whether I'm doing something terribly dumb with Starscream here 😇