Skip to content
Closed
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
40 changes: 40 additions & 0 deletions Tests/SharingTests/SharedTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Dependencies
import Foundation
import IdentifiedCollections
import PerceptionCore
Expand Down Expand Up @@ -35,6 +36,45 @@ import Testing
let a = A()
#expect(a.b.c == C())
}

@Test func lockingOrderWithDependencies() async {
struct D: TestDependencyKey {
@Shared(.inMemory("count")) var count = 0
init() {
Thread.sleep(forTimeInterval: 0.2)
$count.withLock { $0 += 1 }
}
static var testValue: D { D() }
}
let a = Task {
do {
try await Task.sleep(nanoseconds: 100_000_000)
@Dependency(D.self) var d
#expect(d.count == 1)
} catch {}
}
let b = Task {
@Shared(.inMemory("count")) var count: Int = {
Thread.sleep(forTimeInterval: 0.2)
return 2
}()
#expect(count == 1)
}
let c = Task {
do {
try await Task.sleep(nanoseconds: 500_000_000)
Issue.record("Deadlock detected")
exit(1)
} catch {}
}
await withTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
_ = await (a.value, b.value)
c.cancel()
}
taskGroup.addTask { await c.value }
}
}
}

@Suite struct BoxReference {
Expand Down
Loading