Files
Morgan Pretty 08c7a2cf7f Refactored Atomic<T> to @ThreadSafe and @ThreadSafeObject
• Refactored `Atomic<T>` to `@ThreadSafe` and `@ThreadSafeObject` (the latter supports reentrancy
• Added some logging to the debug import process
2024-12-17 14:36:44 +11:00

39 lines
1.1 KiB
Swift

// Copyright © 2024 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import Quick
import Nimble
@testable import SessionUtilitiesKit
class ThreadSafeSpec: QuickSpec {
override class func spec() {
// MARK: - a ThreadSafeObject
describe("a ThreadSafeObject") {
// MARK: -- updates the stored value correctly
it("updates the stored value correctly") {
@ThreadSafeObject var value: Int = 0
expect(value).to(equal(0))
_value.performUpdate { _ in 1 }
expect(value).to(equal(1))
}
// MARK: -- does not crash when doing a reentrant mutation
it("does not crash when doing a reentrant mutation") {
@ThreadSafeObject var value: Int = 0
expect(value).to(equal(0))
_value.performUpdate { _ in
_value.performUpdate { _ in 1 }
expect(value).to(equal(1))
return 2
}
expect(value).to(equal(2))
}
}
}
}