summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ios/MullvadLogging/LogFileOutputStream.swift7
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj2
-rw-r--r--ios/MullvadVPNTests/MullvadLogging/LogRotationTests.swift4
-rw-r--r--ios/MullvadVPNTests/MullvadLogging/LoggingTests.swift6
4 files changed, 12 insertions, 7 deletions
diff --git a/ios/MullvadLogging/LogFileOutputStream.swift b/ios/MullvadLogging/LogFileOutputStream.swift
index 17d335849e..7f4eec3a0b 100644
--- a/ios/MullvadLogging/LogFileOutputStream.swift
+++ b/ios/MullvadLogging/LogFileOutputStream.swift
@@ -75,6 +75,13 @@ class LogFileOutputStream: TextOutputStream {
}
}
+ /// Waits for write operations to finish by issuing a synchronous closure.
+ /// - Note: This function is mainly used in unit tests to facilitate acting
+ /// on disk writes. It should typically not be used in production code.
+ func synchronize() {
+ queue.sync {}
+ }
+
private func writeOnQueue(_ string: String) {
guard let data = string.data(using: encoding) else { return }
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 8c5a8f19ac..0cb01cf7d1 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -2498,8 +2498,8 @@
440E9EFA2BDA976800B1FD11 /* MullvadLogging */ = {
isa = PBXGroup;
children = (
- 7AA513852BC91C6B00D081A4 /* LogRotationTests.swift */,
44B02E3A2BC5732D008EDF34 /* LoggingTests.swift */,
+ 7AA513852BC91C6B00D081A4 /* LogRotationTests.swift */,
);
path = MullvadLogging;
sourceTree = "<group>";
diff --git a/ios/MullvadVPNTests/MullvadLogging/LogRotationTests.swift b/ios/MullvadVPNTests/MullvadLogging/LogRotationTests.swift
index 9ea45fe8e9..a6194bfc98 100644
--- a/ios/MullvadVPNTests/MullvadLogging/LogRotationTests.swift
+++ b/ios/MullvadVPNTests/MullvadLogging/LogRotationTests.swift
@@ -41,10 +41,8 @@ final class LogRotationTests: XCTestCase {
let stream = LogFileOutputStream(fileURL: logPath, header: "", fileSizeLimit: UInt64(totalLogSizeLimit))
for _ in 0 ..< writeOperationCount {
stream.write(stringOfSize(logChunkSize))
-
- // Without sync between every write the test fails on Github.
- sync()
}
+ stream.synchronize()
let actualLogCount = try fileManager.contentsOfDirectory(atPath: directoryPath.relativePath).count
XCTAssertEqual(expectedLogCount, actualLogCount)
diff --git a/ios/MullvadVPNTests/MullvadLogging/LoggingTests.swift b/ios/MullvadVPNTests/MullvadLogging/LoggingTests.swift
index d22222ea3b..e4fc94a91c 100644
--- a/ios/MullvadVPNTests/MullvadLogging/LoggingTests.swift
+++ b/ios/MullvadVPNTests/MullvadLogging/LoggingTests.swift
@@ -10,7 +10,7 @@ import Foundation
@testable import MullvadLogging
import XCTest
-class MullvadLoggingTests: XCTestCase {
+class LoggingTests: XCTestCase {
let fileManager = FileManager.default
var directoryPath: URL!
@@ -33,7 +33,7 @@ class MullvadLoggingTests: XCTestCase {
let fileURL = directoryPath.appendingPathComponent(UUID().uuidString)
let stream = LogFileOutputStream(fileURL: fileURL, header: headerText)
stream.write(logMessage)
- sync()
+ stream.synchronize()
let contents = try XCTUnwrap(String(contentsOf: fileURL))
XCTAssertEqual(contents, "\(headerText)\n\(logMessage)")
@@ -71,7 +71,7 @@ class MullvadLoggingTests: XCTestCase {
logPaths.forEach { url in
let stream = LogFileOutputStream(fileURL: url, header: "")
stream.write("test")
- sync()
+ stream.synchronize()
}
var urls = ApplicationConfiguration.logFileURLs(for: .mainApp, in: directoryPath)