Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test for multiple mutations to file storage. #3479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Tests/ComposableArchitectureTests/FileStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,29 @@
await fulfillment(of: [publisherExpectation], timeout: 1)
}
}

@MainActor
func testMultipleMutations() async throws {
try? FileManager.default.removeItem(at: .documentsDirectory.appending(component: "counts.json"))

try await withDependencies {
$0.defaultFileStorage = .fileSystem
} operation: {
@Shared(.counts) var counts
let delay = 0.5
let time = 5.0
let limit = Int(time / delay)
while counts.count1 < limit {
try await Task.sleep(for: .seconds(delay))
$counts.withLock { $0.count1 += 1 }
$counts.withLock { $0.count2 += 1 }
$counts.withLock { $0.count3 += 1 }
}
XCTAssertEqual(counts.count1, limit)
XCTAssertEqual(counts.count2, limit)
XCTAssertEqual(counts.count3, limit)
}
}
}

extension PersistenceReaderKey
Expand Down Expand Up @@ -513,3 +536,19 @@
return try JSONDecoder().decode([User].self, from: data)
}
}

private struct Counts: Equatable, Codable {
var count1 = 0
var count2 = 0
var count3 = 0
}

extension PersistenceReaderKey
where Self == PersistenceKeyDefault<FileStorageKey<Counts>> {
fileprivate static var counts: Self {
PersistenceKeyDefault(
.fileStorage(.documentsDirectory.appending(component: "counts.json")),

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'documentsDirectory' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'appending(component:directoryHint:)' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'documentsDirectory' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'appending(component:directoryHint:)' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'documentsDirectory' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'appending(component:directoryHint:)' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'documentsDirectory' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'appending(component:directoryHint:)' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'documentsDirectory' is only available in iOS 16.0 or newer

Check failure on line 550 in Tests/ComposableArchitectureTests/FileStorageTests.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'appending(component:directoryHint:)' is only available in iOS 16.0 or newer
Counts()
)
}
}
Loading