Skip to content

Commit cf93a46

Browse files
committed
Add debug information to leak and no leak tests
1 parent 78d0004 commit cf93a46

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

Diff for: ios/MullvadVPNUITests/LeakTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LeakTests: LoggedInWithTimeUITestCase {
3030
.waitForConnectedLabel()
3131

3232
// Keep the tunnel connection for a while
33-
Thread.sleep(forTimeInterval: 30.0)
33+
RunLoop.current.run(until: .now + 30)
3434

3535
TunnelControlPage(app)
3636
.tapDisconnectButton()

Diff for: ios/MullvadVPNUITests/Networking/TrafficGenerator.swift

+71-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ class TrafficGenerator {
2828
using: params
2929
)
3030
setupConnection()
31+
setupOtherHandlers()
3132
}
3233

3334
func reconnect() {
3435
print("Attempting to reconnect")
35-
self.connection.forceCancel()
36+
connection.forceCancel()
3637

3738
connection = recreateConnection()
38-
self.setupConnection()
39+
setupConnection()
40+
setupOtherHandlers()
3941
}
4042

4143
func recreateConnection() -> NWConnection {
@@ -47,6 +49,24 @@ class TrafficGenerator {
4749
)
4850
}
4951

52+
func setupOtherHandlers() {
53+
connection.pathUpdateHandler = { newPath in
54+
let availableInterfaces = newPath.availableInterfaces.map { $0.customDebugDescription }
55+
let availableGateways = newPath.gateways.map { $0.customDebugDescription }
56+
57+
print("New interfaces available: \(availableInterfaces)")
58+
print("New gateways available: \(availableGateways)")
59+
}
60+
61+
connection.viabilityUpdateHandler = { newViability in
62+
print("Connection is viable: \(newViability)")
63+
}
64+
65+
connection.betterPathUpdateHandler = { betterPathAvailable in
66+
print("A better path is available: \(betterPathAvailable)")
67+
}
68+
}
69+
5070
func setupConnection() {
5171
print("Setting up connection...")
5272
let doneAttemptingConnectExpecation = XCTestExpectation(description: "Done attemping to connect")
@@ -84,7 +104,7 @@ class TrafficGenerator {
84104
sendDataTimer.schedule(deadline: .now(), repeating: interval)
85105

86106
sendDataTimer.setEventHandler {
87-
let data = "dGhpcyBpcyBqdXN0IHNvbWUgZHVtbXkgZGF0YSB0aGlzIGlzIGp1c3Qgc29tZSBkdW".data(using: .utf8)
107+
let data = Data("dGhpcyBpcyBqdXN0IHNvbWUgZHVtbXkgZGF0YSB0aGlzIGlzIGp1c3Qgc29tZSBkdW".utf8)
88108

89109
print("Attempting to send data...")
90110

@@ -108,3 +128,51 @@ class TrafficGenerator {
108128
sendDataTimer.cancel()
109129
}
110130
}
131+
132+
extension NWInterface {
133+
var customDebugDescription: String {
134+
"type: \(type) name: \(self.name) index: \(index)"
135+
}
136+
}
137+
138+
extension NWInterface.InterfaceType: @retroactive CustomDebugStringConvertible {
139+
public var debugDescription: String {
140+
switch self {
141+
case .cellular: "Cellular"
142+
case .loopback: "Loopback"
143+
case .other: "Other"
144+
case .wifi: "Wifi"
145+
case .wiredEthernet: "Wired Ethernet"
146+
@unknown default: "Unknown interface type"
147+
}
148+
}
149+
}
150+
151+
extension NWEndpoint {
152+
var customDebugDescription: String {
153+
switch self {
154+
case let .hostPort(host, port): "host: \(host.customDebugDescription) port: \(port)"
155+
case let .opaque(endpoint): "opaque: \(endpoint.description)"
156+
case let .url(url): "url: \(url)"
157+
case let .service(
158+
name,
159+
type,
160+
domain,
161+
interface
162+
): "service named:\(name), type:\(type), domain:\(domain), interface:\(interface?.customDebugDescription ?? "[No interface]")"
163+
case let .unix(path): "unix: \(path)"
164+
@unknown default: "Unknown NWEndpoint type"
165+
}
166+
}
167+
}
168+
169+
extension NWEndpoint.Host {
170+
var customDebugDescription: String {
171+
switch self {
172+
case let .ipv4(IPv4Address): "IPv4: \(IPv4Address)"
173+
case let .ipv6(IPv6Address): "IPv6: \(IPv6Address)"
174+
case let .name(name, interface): "named: \(name), \(interface?.customDebugDescription ?? "[No interface]")"
175+
@unknown default: "Unknown host"
176+
}
177+
}
178+
}

0 commit comments

Comments
 (0)