Skip to content

Commit

Permalink
Fix failing log rotation test
Browse files Browse the repository at this point in the history
  • Loading branch information
rablador committed Oct 7, 2024
1 parent 0e32a21 commit e23480f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ios/MullvadLogging/LogFileOutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class LogFileOutputStream: TextOutputStream {
}
}

/// Waits for write operations to finish by issuing a synchronous closure.
func synchronize() {
queue.sync {}
}

private func writeOnQueue(_ string: String) {
guard let data = string.data(using: encoding) else { return }

Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2496,8 +2496,8 @@
440E9EFA2BDA976800B1FD11 /* MullvadLogging */ = {
isa = PBXGroup;
children = (
7AA513852BC91C6B00D081A4 /* LogRotationTests.swift */,
44B02E3A2BC5732D008EDF34 /* LoggingTests.swift */,
7AA513852BC91C6B00D081A4 /* LogRotationTests.swift */,
);
path = MullvadLogging;
sourceTree = "<group>";
Expand Down
4 changes: 1 addition & 3 deletions ios/MullvadVPNTests/MullvadLogging/LogRotationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ios/MullvadVPNTests/MullvadLogging/LoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
@testable import MullvadLogging
import XCTest

class MullvadLoggingTests: XCTestCase {
class LoggingTests: XCTestCase {
let fileManager = FileManager.default
var directoryPath: URL!

Expand All @@ -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)")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e23480f

Please sign in to comment.