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

Refactor URLSession out of outgoing connection proxy tests #5446

Conversation

rablador
Copy link
Contributor

@rablador rablador commented Nov 16, 2023


This change is Reviewable

Copy link

linear bot commented Nov 16, 2023

IOS-383 Refactor the URLSession out of `OutgoingConnectionProxy`

  • It will help us remove a lot of custom written code for tests

See this comment for the reason why.

It should be a janitor task

@rablador rablador force-pushed the refactor-the-urlsession-out-of-outgoingconnectionproxy-ios-383 branch from 24528e9 to d7233a2 Compare November 16, 2023 11:00
Copy link
Contributor Author

@rablador rablador left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion


ios/MullvadVPNTests/OutgoingConnectionProxyTests.swift line 30 at r1 (raw file):

    }

    func testNoInternetConnection() async throws {

Ok to remove this test? It relies on the previoud MockURLProtocol to work and isn't really compatible with the refactor.

@rablador rablador force-pushed the refactor-the-urlsession-out-of-outgoingconnectionproxy-ios-383 branch 2 times, most recently from 3d9eec2 to 110dddd Compare November 16, 2023 12:13
Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 6 files at r1, 1 of 2 files at r2.
Reviewable status: 5 of 6 files reviewed, 4 unresolved discussions (waiting on @rablador)


ios/MullvadVPN/GeneralAPIs/OutgoingConnectionProxy.swift line 72 at r2 (raw file):

            throw REST.Error.network(URLError(.badURL))
        }
        let request = URLRequest(

This is not used anymore since we are using func data(from url: URL) async throws -> (Data, URLResponse) instead.

If that was intentional, please delete this variable.
If it wasn't, please adjust the protocol accordingly.


ios/MullvadVPNTests/MockURLSession.swift line 11 at r2 (raw file):

import Foundation

class MockURLSession: URLSessionProtocol {

Let's rename this URLSessionStub
(I never get tired of posting this article 🤠)


ios/MullvadVPNTests/OutgoingConnectionProxyTests.swift line 30 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

Ok to remove this test? It relies on the previoud MockURLProtocol to work and isn't really compatible with the refactor.

I think that's okay.
On the other hand, it would be nice if we could have a test that validates the retry logic of OutgoingConnectionProxy


ios/MullvadVPNTests/OutgoingConnectionProxyTests.swift line 85 at r2 (raw file):

extension OutgoingConnectionProxyTests {
    private enum IPVersion: String {

If ExitIPVersion wasn't declared as a private enum to OutgoingConnectionProxy
we could reuse it here instead of declaring a similar type

I think it's worth making ExitIPVersion internal, for that purpose, and declare it outside of OutgoingConnectionProxy

@buggmagnet buggmagnet added the iOS Issues related to iOS label Nov 16, 2023
Copy link
Contributor Author

@rablador rablador left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 of 6 files reviewed, 4 unresolved discussions (waiting on @buggmagnet)


ios/MullvadVPN/GeneralAPIs/OutgoingConnectionProxy.swift line 72 at r2 (raw file):

Previously, buggmagnet wrote…

This is not used anymore since we are using func data(from url: URL) async throws -> (Data, URLResponse) instead.

If that was intentional, please delete this variable.
If it wasn't, please adjust the protocol accordingly.

Forgot to remove, but on second thought I think should just keep it and adjust the protocol. I don't believe the custom timeout matters much here, but is is more consistent.


ios/MullvadVPNTests/MockURLSession.swift line 11 at r2 (raw file):

Previously, buggmagnet wrote…

Let's rename this URLSessionStub
(I never get tired of posting this article 🤠)

Done.


ios/MullvadVPNTests/OutgoingConnectionProxyTests.swift line 85 at r2 (raw file):

Previously, buggmagnet wrote…

If ExitIPVersion wasn't declared as a private enum to OutgoingConnectionProxy
we could reuse it here instead of declaring a similar type

I think it's worth making ExitIPVersion internal, for that purpose, and declare it outside of OutgoingConnectionProxy

Done.

@rablador rablador force-pushed the refactor-the-urlsession-out-of-outgoingconnectionproxy-ios-383 branch from 110dddd to 6823193 Compare November 17, 2023 08:42
Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

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

Nice job !

Reviewed 5 of 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @rablador)


ios/MullvadVPN/GeneralAPIs/OutgoingConnectionProxy.swift line 72 at r2 (raw file):

Previously, rablador (Jon Petersson) wrote…

Forgot to remove, but on second thought I think should just keep it and adjust the protocol. I don't believe the custom timeout matters much here, but is is more consistent.

IIRC the default timeout for URLRequest is 60 seconds, so slightly different.
But I agree with you on the consistent values 👍

@rablador rablador force-pushed the refactor-the-urlsession-out-of-outgoingconnectionproxy-ios-383 branch from 6823193 to dc746f1 Compare November 20, 2023 08:58
@buggmagnet buggmagnet merged commit 1612678 into main Nov 20, 2023
4 of 5 checks passed
@buggmagnet buggmagnet deleted the refactor-the-urlsession-out-of-outgoingconnectionproxy-ios-383 branch November 20, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants