From 10066b5df96510f7eb84d19a638f75e16935863b Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 4 Feb 2025 10:35:25 +0000 Subject: [PATCH] Make the FileSystem world strict concurrency clean Motivation: We have a few other file system modules with a small amount of code, and a lot of tests. Most of these require no changes for strict concurrency, so let's tackle them all. Modifications: Strict concurrency for filesystem targets enabled. Fixed a few incorrect test case captures. Result: Strict concurrency clean filesystem bits. --- Package.swift | 14 +++++++++----- .../FileSystemTests.swift | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Package.swift b/Package.swift index f88ea97464..072cb99b9e 100644 --- a/Package.swift +++ b/Package.swift @@ -256,7 +256,8 @@ let package = Package( dependencies: [ "_NIOFileSystem" ], - path: "Sources/_NIOFileSystemExported" + path: "Sources/_NIOFileSystemExported", + swiftSettings: strictConcurrencySettings ), .target( name: "_NIOFileSystemFoundationCompat", @@ -264,7 +265,8 @@ let package = Package( "_NIOFileSystem", "NIOFoundationCompat", ], - path: "Sources/NIOFileSystemFoundationCompat" + path: "Sources/NIOFileSystemFoundationCompat", + swiftSettings: strictConcurrencySettings ), // MARK: - Examples @@ -543,7 +545,7 @@ let package = Package( swiftCollections, swiftSystem, ], - swiftSettings: [ + swiftSettings: strictConcurrencySettings + [ .define("ENABLE_MOCKING", .when(configuration: .debug)) ] ), @@ -560,14 +562,16 @@ let package = Package( // for the integration tests. Exclude the whole tree from // the build. "Test Data" - ] + ], + swiftSettings: strictConcurrencySettings ), .testTarget( name: "NIOFileSystemFoundationCompatTests", dependencies: [ "_NIOFileSystem", "_NIOFileSystemFoundationCompat", - ] + ], + swiftSettings: strictConcurrencySettings ), ] ) diff --git a/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift b/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift index d0f5194db7..4e82f74054 100644 --- a/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift +++ b/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift @@ -585,9 +585,9 @@ final class FileSystemTests: XCTestCase { func testCopyLargeFile() async throws { let sourcePath = try await self.fs.temporaryFilePath() let destPath = try await self.fs.temporaryFilePath() - self.addTeardownBlock { - _ = try? await self.fs.removeItem(at: sourcePath, strategy: .platformDefault) - _ = try? await self.fs.removeItem(at: destPath, strategy: .platformDefault) + self.addTeardownBlock { [fs] in + _ = try? await fs.removeItem(at: sourcePath, strategy: .platformDefault) + _ = try? await fs.removeItem(at: destPath, strategy: .platformDefault) } let sourceInfo = try await self.fs.withFileHandle( @@ -854,7 +854,7 @@ final class FileSystemTests: XCTestCase { _ copyStrategy: CopyStrategy, _ description: String, _ path: FilePath, - triggerCancel: @escaping (DirectoryEntry) -> Bool, + triggerCancel: @escaping @Sendable (DirectoryEntry) -> Bool, line: UInt = #line ) async throws { @@ -863,8 +863,8 @@ final class FileSystemTests: XCTestCase { let requestedCancel = NIOLockedValueBox(false) let cancelRequested = expectation(description: "cancel requested") - let task = Task { - try await self.fs.copyItem(at: path, to: copyPath, strategy: copyStrategy) { _, error in + let task = Task { [fs] in + try await fs.copyItem(at: path, to: copyPath, strategy: copyStrategy) { _, error in throw error } shouldCopyItem: { source, destination in // Abuse shouldCopy to trigger the cancellation after getting some way in.