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

Fix race condition in FileStorageKey #3479

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixes
mbrandonw committed Nov 12, 2024
commit bc8ee05fe0005b19e659df620ba25049fe4d8b71
12 changes: 9 additions & 3 deletions Tests/ComposableArchitectureTests/FileStorageTests.swift
Original file line number Diff line number Diff line change
@@ -474,7 +474,9 @@ final class FileStorageTests: XCTestCase {

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

try await withDependencies {
$0.defaultFileStorage = .fileSystem
@@ -496,7 +498,9 @@ final class FileStorageTests: XCTestCase {
}

func testMultipleMutationsFromMultipleThreads() async throws {
try? FileManager.default.removeItem(at: .documentsDirectory.appending(component: "counts.json"))
try? FileManager.default.removeItem(
at: URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("counts.json")
)

await withDependencies {
$0.defaultFileStorage = .fileSystem
@@ -563,7 +567,9 @@ extension [URL: Data] {
extension PersistenceKey where Self == PersistenceKeyDefault<FileStorageKey<[Int: Int]>> {
fileprivate static var counts: Self {
Self(
.fileStorage(.documentsDirectory.appending(component: "counts.json")),
.fileStorage(
URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("counts.json")
),
[:]
)
}