diff --git a/Package.swift b/Package.swift index a025ff1e86..68d2550c2e 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "Verge", platforms: [ .macOS(.v11), - .iOS(.v16), + .iOS(.v13), .tvOS(.v13), .watchOS(.v6), ], diff --git a/Tests/VergeTests/ConcurrencyTests.swift b/Tests/VergeTests/ConcurrencyTests.swift index 879b594936..fe84fa690f 100644 --- a/Tests/VergeTests/ConcurrencyTests.swift +++ b/Tests/VergeTests/ConcurrencyTests.swift @@ -74,17 +74,18 @@ final class ConcurrencyTests: XCTestCase { let store1 = DemoStore() let exp = expectation(description: "11") - let count = OSAllocatedUnfairLock.init(initialState: 0) + + let count = VergeConcurrency.UnfairLockAtomic.init(0) DispatchQueue.global().async { let cancellable = store1.sinkState(queue: .startsFromCurrentThread(andUse: .mainIsolated())) { state in defer { - count.withLock { $0 += 1 } + count.modify { $0 += 1 } } - if count.withLock({ $0 == 0 }) { + if count.modify({ $0 == 0 }) { XCTAssertEqual(Thread.isMainThread, false) } else { XCTAssertEqual(Thread.isMainThread, true) @@ -109,12 +110,12 @@ final class ConcurrencyTests: XCTestCase { for i in 0..<100 { do { - let version = OSAllocatedUnfairLock.init(initialState: 0) + let version = VergeConcurrency.UnfairLockAtomic.init(0) store.sinkState(queue: .passthrough) { s in - if version.withLock({ $0 > s.version }) { + if version.modify({ $0 > s.version }) { XCTFail() } - version.withLock { $0 = s.version } + version.modify { $0 = s.version } print("\(i)", s.version) } .store(in: &bag) @@ -122,12 +123,12 @@ final class ConcurrencyTests: XCTestCase { } do { - let version = OSAllocatedUnfairLock.init(initialState: 0) + let version = VergeConcurrency.UnfairLockAtomic.init(0) store.sinkState(queue: .passthrough) { s in - if version.withLock({ $0 > s.version }) { + if version.modify({ $0 > s.version }) { XCTFail() } - version.withLock { $0 = s.version } + version.modify { $0 = s.version } print("x", s.version) store.commit { if s.count == 1 { diff --git a/Tests/VergeTests/PipelineTests.swift b/Tests/VergeTests/PipelineTests.swift index ab3cd4b936..875cc0ce6b 100644 --- a/Tests/VergeTests/PipelineTests.swift +++ b/Tests/VergeTests/PipelineTests.swift @@ -1,20 +1,21 @@ import XCTest import Verge -import os.lock final class PipelineTests: XCTestCase { func test_MapPipeline() { - - let mapCounter = OSAllocatedUnfairLock.init(initialState: 0) + + let mapCounter = VergeConcurrency.UnfairLockAtomic.init(0) let pipeline = Pipelines.ChangesMapPipeline( intermediate: { $0 }, transform: { - mapCounter.withLock { $0 += 1 } + mapCounter.modify { + $0 += 1 + } return $0.name.count }, additionalDropCondition: nil @@ -33,7 +34,7 @@ final class PipelineTests: XCTestCase { .noUpdates ) - XCTAssertEqual(mapCounter.withLock { $0 }, 0) + XCTAssertEqual(mapCounter.value, 0) } do { @@ -48,7 +49,7 @@ final class PipelineTests: XCTestCase { .noUpdates ) - XCTAssertEqual(mapCounter.withLock { $0 }, 2) + XCTAssertEqual(mapCounter.value , 2) } @@ -56,14 +57,14 @@ final class PipelineTests: XCTestCase { func test_MapPipeline_Intermediate() { - let mapCounter = OSAllocatedUnfairLock.init(initialState: 0) + let mapCounter = VergeConcurrency.UnfairLockAtomic.init(0) let pipeline = Pipelines.ChangesMapPipeline( intermediate: { $0.name }, transform: { - mapCounter.withLock { $0 += 1 } + mapCounter.modify { $0 += 1 } return $0.count }, additionalDropCondition: nil @@ -82,7 +83,7 @@ final class PipelineTests: XCTestCase { .noUpdates ) - XCTAssertEqual(mapCounter.withLock { $0 }, 0) + XCTAssertEqual(mapCounter.value, 0) } do { @@ -97,7 +98,7 @@ final class PipelineTests: XCTestCase { .noUpdates ) - XCTAssertEqual(mapCounter.withLock { $0 }, 0) + XCTAssertEqual(mapCounter.value, 0) } diff --git a/Tests/VergeTests/VergeStoreTests.swift b/Tests/VergeTests/VergeStoreTests.swift index 2375981782..256b8dab50 100644 --- a/Tests/VergeTests/VergeStoreTests.swift +++ b/Tests/VergeTests/VergeStoreTests.swift @@ -216,10 +216,10 @@ final class VergeStoreTests: XCTestCase { let store = DemoStore() - let count = OSAllocatedUnfairLock.init(initialState: 0) + let count = VergeConcurrency.UnfairLockAtomic.init(0) let subs = store.sinkState(queue: .passthrough) { (_) in - count.withLock { $0 += 1 } + count.modify { $0 += 1 } } XCTAssertEqual(store.state.version, 0) @@ -256,7 +256,7 @@ final class VergeStoreTests: XCTestCase { } XCTAssertEqual(store.state.version, 2) - XCTAssertEqual(count.withLock { $0 }, 3) + XCTAssertEqual(count.value, 3) withExtendedLifetime(subs, {}) @@ -308,10 +308,10 @@ final class VergeStoreTests: XCTestCase { func testSubscription() { var subscriptions = Set() - let count = OSAllocatedUnfairLock.init(initialState: 0) + let count = VergeConcurrency.UnfairLockAtomic.init(0) store.sinkState(queue: .passthrough) { (changes) in - count.withLock { + count.modify { $0 += 1 } } @@ -328,7 +328,7 @@ final class VergeStoreTests: XCTestCase { $0.markAsModified() } - XCTAssertEqual(count.withLock { $0 }, 2) + XCTAssertEqual(count.value, 2) }