Skip to content

Commit

Permalink
Bucket effect cancel IDs. (#3374)
Browse files Browse the repository at this point in the history
* Bucket effect cancel IDs.

* wip

* wip

* remove cache reset

* wip

* wip

* wip
  • Loading branch information
mbrandonw committed Sep 12, 2024
1 parent 912192b commit 03ad0cc
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "3ef38bb702a1a2f39c7e19fc0578403b8ee52b17",
"version" : "1.3.9"
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
"version" : "1.4.0"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-docc-plugin",
"state" : {
"revision" : "2eb22993b3dfd0c0d32729b357c8dabb6cd44680",
"version" : "1.4.2"
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
"version" : "1.4.3"
}
},
{
Expand Down Expand Up @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
"version" : "1.17.4"
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
"version" : "1.17.5"
}
},
{
Expand All @@ -158,8 +158,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "96beb108a57f24c8476ae1f309239270772b2940",
"version" : "1.2.5"
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
"version" : "1.4.0"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "3ef38bb702a1a2f39c7e19fc0578403b8ee52b17",
"version" : "1.3.9"
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
"version" : "1.4.0"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-docc-plugin",
"state" : {
"revision" : "2eb22993b3dfd0c0d32729b357c8dabb6cd44680",
"version" : "1.4.2"
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
"version" : "1.4.3"
}
},
{
Expand Down Expand Up @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
"version" : "1.17.4"
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
"version" : "1.17.5"
}
},
{
Expand All @@ -167,8 +167,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "96beb108a57f24c8476ae1f309239270772b2940",
"version" : "1.2.5"
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
"version" : "1.4.0"
}
}
],
Expand Down
30 changes: 15 additions & 15 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "71344dd930fde41e8f3adafe260adcbb2fc2a3dc",
"version" : "1.5.4"
"revision" : "642e6aab8e03e5f992d9c83e38c5be98cfad5078",
"version" : "1.5.5"
}
},
{
Expand All @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d",
"version" : "1.1.2"
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
}
},
{
Expand All @@ -77,17 +77,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "3ef38bb702a1a2f39c7e19fc0578403b8ee52b17",
"version" : "1.3.9"
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
"version" : "1.4.0"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-docc-plugin",
"state" : {
"revision" : "0510d9160330025fb5823f7845c26af3cd56a405",
"version" : "1.4.1"
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
"version" : "1.4.3"
}
},
{
Expand Down Expand Up @@ -122,8 +122,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-navigation",
"state" : {
"revision" : "4d04eb04807dc3176515184abe08c3adcbb04713",
"version" : "2.1.0"
"revision" : "e834b3760731160d7d448509ee6a1408c8582a6b",
"version" : "2.2.0"
}
},
{
Expand All @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
"version" : "1.17.4"
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
"version" : "1.17.5"
}
},
{
Expand All @@ -150,16 +150,16 @@
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "515f79b522918f83483068d99c68daeb5116342d",
"version" : "600.0.0-prerelease-2024-08-20"
"version" : "600.0.0-prerelease-2024-09-04"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "96beb108a57f24c8476ae1f309239270772b2940",
"version" : "1.2.5"
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
"version" : "1.4.0"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.3.5"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
],
Expand Down
4 changes: 2 additions & 2 deletions Package@swift-6.0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.3.5"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
],
Expand Down
7 changes: 7 additions & 0 deletions Sources/ComposableArchitecture/Effects/Cancellation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,18 @@ extension Task<Never, Never> {
let discriminator: ObjectIdentifier
let id: AnyHashable
let navigationIDPath: NavigationIDPath
let testIdentifier: TestContext.Testing.Test.ID?

init(id: some Hashable, navigationIDPath: NavigationIDPath) {
self.discriminator = ObjectIdentifier(type(of: id))
self.id = id
self.navigationIDPath = navigationIDPath
switch TestContext.current {
case let .swiftTesting(.some(testing)):
self.testIdentifier = testing.test.id
default:
self.testIdentifier = nil
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions Sources/ComposableArchitecture/TestStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,6 @@ public final class TestStore<State, Action> {
where State: Equatable, R.State == State, R.Action == Action {
let sharedChangeTracker = SharedChangeTracker()
let reducer = Dependencies.withDependencies {
if TestContext.current == .swiftTesting {
$0.resetCache()
}
prepareDependencies(&$0)
$0.sharedChangeTrackers.insert(sharedChangeTracker)
} operation: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#if canImport(Testing)
import ComposableArchitecture
import Testing

@Suite
struct EffectCancellationIsolationTests {
@Test
func testIsolation1() async {
let store = await TestStore(initialState: Feature.State()) {
Feature()
}
await store.send(.start)
await store.receive(\.response) {
$0.value = 42
}
await store.send(.stop)
}

@Test
func testIsolation2() async {
let store = await TestStore(initialState: Feature.State()) {
Feature()
}
await store.send(.start)
await store.receive(\.response) {
$0.value = 42
}
await store.send(.stop)
}
}

@Reducer
private struct Feature {
struct State: Equatable {
var value = 0
}
enum Action {
case response(Int)
case start
case stop
}
enum CancelID { case longLiving }
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .response(let value):
state.value = value
return .none
case .start:
return .run { send in
await send(.response(42))
try await Task.never()
}
.cancellable(id: CancelID.longLiving, cancelInFlight: true)
case .stop:
return .cancel(id: CancelID.longLiving)
}
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ final class EffectCancellationTests: BaseTCATestCase {
self.cancellables.removeAll()
}

override func invokeTest() {
withMainSerialExecutor {
super.invokeTest()
}
}

func testCancellation() async {
let values = LockIsolated<[Int]>([])

Expand Down

0 comments on commit 03ad0cc

Please sign in to comment.