summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBug Magnet <marco.nikic@mullvad.net>2025-01-29 17:05:35 +0100
committerBug Magnet <marco.nikic@mullvad.net>2025-02-06 15:43:21 +0100
commitcf93a4607e9773e86a089d098ac2e02d892e84a5 (patch)
tree3a20ea9009bd0b94486eaf9aad57dbca8a8b32fe
parent78d00040c816ad24d6b237fd3310a3a9e21dfec5 (diff)
downloadmullvadvpn-cf93a4607e9773e86a089d098ac2e02d892e84a5.tar.xz
mullvadvpn-cf93a4607e9773e86a089d098ac2e02d892e84a5.zip
Add debug information to leak and no leak tests
-rw-r--r--ios/MullvadVPNUITests/LeakTests.swift2
-rw-r--r--ios/MullvadVPNUITests/Networking/TrafficGenerator.swift74
2 files changed, 72 insertions, 4 deletions
diff --git a/ios/MullvadVPNUITests/LeakTests.swift b/ios/MullvadVPNUITests/LeakTests.swift
index 1ad640f9a3..d1c3d6b786 100644
--- a/ios/MullvadVPNUITests/LeakTests.swift
+++ b/ios/MullvadVPNUITests/LeakTests.swift
@@ -30,7 +30,7 @@ class LeakTests: LoggedInWithTimeUITestCase {
.waitForConnectedLabel()
// Keep the tunnel connection for a while
- Thread.sleep(forTimeInterval: 30.0)
+ RunLoop.current.run(until: .now + 30)
TunnelControlPage(app)
.tapDisconnectButton()
diff --git a/ios/MullvadVPNUITests/Networking/TrafficGenerator.swift b/ios/MullvadVPNUITests/Networking/TrafficGenerator.swift
index 335a1b6455..6e9faaad2b 100644
--- a/ios/MullvadVPNUITests/Networking/TrafficGenerator.swift
+++ b/ios/MullvadVPNUITests/Networking/TrafficGenerator.swift
@@ -28,14 +28,16 @@ class TrafficGenerator {
using: params
)
setupConnection()
+ setupOtherHandlers()
}
func reconnect() {
print("Attempting to reconnect")
- self.connection.forceCancel()
+ connection.forceCancel()
connection = recreateConnection()
- self.setupConnection()
+ setupConnection()
+ setupOtherHandlers()
}
func recreateConnection() -> NWConnection {
@@ -47,6 +49,24 @@ class TrafficGenerator {
)
}
+ func setupOtherHandlers() {
+ connection.pathUpdateHandler = { newPath in
+ let availableInterfaces = newPath.availableInterfaces.map { $0.customDebugDescription }
+ let availableGateways = newPath.gateways.map { $0.customDebugDescription }
+
+ print("New interfaces available: \(availableInterfaces)")
+ print("New gateways available: \(availableGateways)")
+ }
+
+ connection.viabilityUpdateHandler = { newViability in
+ print("Connection is viable: \(newViability)")
+ }
+
+ connection.betterPathUpdateHandler = { betterPathAvailable in
+ print("A better path is available: \(betterPathAvailable)")
+ }
+ }
+
func setupConnection() {
print("Setting up connection...")
let doneAttemptingConnectExpecation = XCTestExpectation(description: "Done attemping to connect")
@@ -84,7 +104,7 @@ class TrafficGenerator {
sendDataTimer.schedule(deadline: .now(), repeating: interval)
sendDataTimer.setEventHandler {
- let data = "dGhpcyBpcyBqdXN0IHNvbWUgZHVtbXkgZGF0YSB0aGlzIGlzIGp1c3Qgc29tZSBkdW".data(using: .utf8)
+ let data = Data("dGhpcyBpcyBqdXN0IHNvbWUgZHVtbXkgZGF0YSB0aGlzIGlzIGp1c3Qgc29tZSBkdW".utf8)
print("Attempting to send data...")
@@ -108,3 +128,51 @@ class TrafficGenerator {
sendDataTimer.cancel()
}
}
+
+extension NWInterface {
+ var customDebugDescription: String {
+ "type: \(type) name: \(self.name) index: \(index)"
+ }
+}
+
+extension NWInterface.InterfaceType: @retroactive CustomDebugStringConvertible {
+ public var debugDescription: String {
+ switch self {
+ case .cellular: "Cellular"
+ case .loopback: "Loopback"
+ case .other: "Other"
+ case .wifi: "Wifi"
+ case .wiredEthernet: "Wired Ethernet"
+ @unknown default: "Unknown interface type"
+ }
+ }
+}
+
+extension NWEndpoint {
+ var customDebugDescription: String {
+ switch self {
+ case let .hostPort(host, port): "host: \(host.customDebugDescription) port: \(port)"
+ case let .opaque(endpoint): "opaque: \(endpoint.description)"
+ case let .url(url): "url: \(url)"
+ case let .service(
+ name,
+ type,
+ domain,
+ interface
+ ): "service named:\(name), type:\(type), domain:\(domain), interface:\(interface?.customDebugDescription ?? "[No interface]")"
+ case let .unix(path): "unix: \(path)"
+ @unknown default: "Unknown NWEndpoint type"
+ }
+ }
+}
+
+extension NWEndpoint.Host {
+ var customDebugDescription: String {
+ switch self {
+ case let .ipv4(IPv4Address): "IPv4: \(IPv4Address)"
+ case let .ipv6(IPv6Address): "IPv6: \(IPv6Address)"
+ case let .name(name, interface): "named: \(name), \(interface?.customDebugDescription ?? "[No interface]")"
+ @unknown default: "Unknown host"
+ }
+ }
+}