mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
• Refactored `Atomic<T>` to `@ThreadSafe` and `@ThreadSafeObject` (the latter supports reentrancy • Added some logging to the debug import process
39 lines
1.1 KiB
Swift
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))
|
|
}
|
|
}
|
|
}
|
|
}
|