Skip to content

Commit 03ad0cc

Browse files
authored
Bucket effect cancel IDs. (pointfreeco#3374)
* Bucket effect cancel IDs. * wip * wip * remove cache reset * wip * wip * wip
1 parent 912192b commit 03ad0cc

File tree

9 files changed

+110
-38
lines changed

9 files changed

+110
-38
lines changed

.github/package.xcworkspace/xcshareddata/swiftpm/Package.resolved

+8-8
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@
7777
"kind" : "remoteSourceControl",
7878
"location" : "https://github.com/pointfreeco/swift-dependencies",
7979
"state" : {
80-
"revision" : "3ef38bb702a1a2f39c7e19fc0578403b8ee52b17",
81-
"version" : "1.3.9"
80+
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
81+
"version" : "1.4.0"
8282
}
8383
},
8484
{
8585
"identity" : "swift-docc-plugin",
8686
"kind" : "remoteSourceControl",
8787
"location" : "https://github.com/swiftlang/swift-docc-plugin",
8888
"state" : {
89-
"revision" : "2eb22993b3dfd0c0d32729b357c8dabb6cd44680",
90-
"version" : "1.4.2"
89+
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
90+
"version" : "1.4.3"
9191
}
9292
},
9393
{
@@ -140,8 +140,8 @@
140140
"kind" : "remoteSourceControl",
141141
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
142142
"state" : {
143-
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
144-
"version" : "1.17.4"
143+
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
144+
"version" : "1.17.5"
145145
}
146146
},
147147
{
@@ -158,8 +158,8 @@
158158
"kind" : "remoteSourceControl",
159159
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
160160
"state" : {
161-
"revision" : "96beb108a57f24c8476ae1f309239270772b2940",
162-
"version" : "1.2.5"
161+
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
162+
"version" : "1.4.0"
163163
}
164164
}
165165
],

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

+8-8
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@
7777
"kind" : "remoteSourceControl",
7878
"location" : "https://github.com/pointfreeco/swift-dependencies",
7979
"state" : {
80-
"revision" : "3ef38bb702a1a2f39c7e19fc0578403b8ee52b17",
81-
"version" : "1.3.9"
80+
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
81+
"version" : "1.4.0"
8282
}
8383
},
8484
{
8585
"identity" : "swift-docc-plugin",
8686
"kind" : "remoteSourceControl",
8787
"location" : "https://github.com/swiftlang/swift-docc-plugin",
8888
"state" : {
89-
"revision" : "2eb22993b3dfd0c0d32729b357c8dabb6cd44680",
90-
"version" : "1.4.2"
89+
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
90+
"version" : "1.4.3"
9191
}
9292
},
9393
{
@@ -140,8 +140,8 @@
140140
"kind" : "remoteSourceControl",
141141
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
142142
"state" : {
143-
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
144-
"version" : "1.17.4"
143+
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
144+
"version" : "1.17.5"
145145
}
146146
},
147147
{
@@ -167,8 +167,8 @@
167167
"kind" : "remoteSourceControl",
168168
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
169169
"state" : {
170-
"revision" : "96beb108a57f24c8476ae1f309239270772b2940",
171-
"version" : "1.2.5"
170+
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
171+
"version" : "1.4.0"
172172
}
173173
}
174174
],

Package.resolved

+15-15
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"kind" : "remoteSourceControl",
3333
"location" : "https://github.com/pointfreeco/swift-case-paths",
3434
"state" : {
35-
"revision" : "71344dd930fde41e8f3adafe260adcbb2fc2a3dc",
36-
"version" : "1.5.4"
35+
"revision" : "642e6aab8e03e5f992d9c83e38c5be98cfad5078",
36+
"version" : "1.5.5"
3737
}
3838
},
3939
{
@@ -50,8 +50,8 @@
5050
"kind" : "remoteSourceControl",
5151
"location" : "https://github.com/apple/swift-collections",
5252
"state" : {
53-
"revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d",
54-
"version" : "1.1.2"
53+
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
54+
"version" : "1.1.3"
5555
}
5656
},
5757
{
@@ -77,17 +77,17 @@
7777
"kind" : "remoteSourceControl",
7878
"location" : "https://github.com/pointfreeco/swift-dependencies",
7979
"state" : {
80-
"revision" : "3ef38bb702a1a2f39c7e19fc0578403b8ee52b17",
81-
"version" : "1.3.9"
80+
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
81+
"version" : "1.4.0"
8282
}
8383
},
8484
{
8585
"identity" : "swift-docc-plugin",
8686
"kind" : "remoteSourceControl",
8787
"location" : "https://github.com/swiftlang/swift-docc-plugin",
8888
"state" : {
89-
"revision" : "0510d9160330025fb5823f7845c26af3cd56a405",
90-
"version" : "1.4.1"
89+
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
90+
"version" : "1.4.3"
9191
}
9292
},
9393
{
@@ -122,8 +122,8 @@
122122
"kind" : "remoteSourceControl",
123123
"location" : "https://github.com/pointfreeco/swift-navigation",
124124
"state" : {
125-
"revision" : "4d04eb04807dc3176515184abe08c3adcbb04713",
126-
"version" : "2.1.0"
125+
"revision" : "e834b3760731160d7d448509ee6a1408c8582a6b",
126+
"version" : "2.2.0"
127127
}
128128
},
129129
{
@@ -140,8 +140,8 @@
140140
"kind" : "remoteSourceControl",
141141
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
142142
"state" : {
143-
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
144-
"version" : "1.17.4"
143+
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
144+
"version" : "1.17.5"
145145
}
146146
},
147147
{
@@ -150,16 +150,16 @@
150150
"location" : "https://github.com/swiftlang/swift-syntax",
151151
"state" : {
152152
"revision" : "515f79b522918f83483068d99c68daeb5116342d",
153-
"version" : "600.0.0-prerelease-2024-08-20"
153+
"version" : "600.0.0-prerelease-2024-09-04"
154154
}
155155
},
156156
{
157157
"identity" : "xctest-dynamic-overlay",
158158
"kind" : "remoteSourceControl",
159159
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
160160
"state" : {
161-
"revision" : "96beb108a57f24c8476ae1f309239270772b2940",
162-
"version" : "1.2.5"
161+
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
162+
"version" : "1.4.0"
163163
}
164164
}
165165
],

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ let package = Package(
2424
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
2525
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
2626
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
27-
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.3.5"),
27+
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2929
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
3030
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
3131
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
32-
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
32+
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
3333
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
3434
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
3535
],

[email protected]

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ let package = Package(
2424
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
2525
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
2626
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
27-
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.3.5"),
27+
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2929
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
3030
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
3131
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
32-
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
32+
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
3333
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
3434
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
3535
],

Sources/ComposableArchitecture/Effects/Cancellation.swift

+7
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,18 @@ extension Task<Never, Never> {
244244
let discriminator: ObjectIdentifier
245245
let id: AnyHashable
246246
let navigationIDPath: NavigationIDPath
247+
let testIdentifier: TestContext.Testing.Test.ID?
247248

248249
init(id: some Hashable, navigationIDPath: NavigationIDPath) {
249250
self.discriminator = ObjectIdentifier(type(of: id))
250251
self.id = id
251252
self.navigationIDPath = navigationIDPath
253+
switch TestContext.current {
254+
case let .swiftTesting(.some(testing)):
255+
self.testIdentifier = testing.test.id
256+
default:
257+
self.testIdentifier = nil
258+
}
252259
}
253260
}
254261

Sources/ComposableArchitecture/TestStore.swift

-3
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,6 @@ public final class TestStore<State, Action> {
535535
where State: Equatable, R.State == State, R.Action == Action {
536536
let sharedChangeTracker = SharedChangeTracker()
537537
let reducer = Dependencies.withDependencies {
538-
if TestContext.current == .swiftTesting {
539-
$0.resetCache()
540-
}
541538
prepareDependencies(&$0)
542539
$0.sharedChangeTrackers.insert(sharedChangeTracker)
543540
} operation: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#if canImport(Testing)
2+
import ComposableArchitecture
3+
import Testing
4+
5+
@Suite
6+
struct EffectCancellationIsolationTests {
7+
@Test
8+
func testIsolation1() async {
9+
let store = await TestStore(initialState: Feature.State()) {
10+
Feature()
11+
}
12+
await store.send(.start)
13+
await store.receive(\.response) {
14+
$0.value = 42
15+
}
16+
await store.send(.stop)
17+
}
18+
19+
@Test
20+
func testIsolation2() async {
21+
let store = await TestStore(initialState: Feature.State()) {
22+
Feature()
23+
}
24+
await store.send(.start)
25+
await store.receive(\.response) {
26+
$0.value = 42
27+
}
28+
await store.send(.stop)
29+
}
30+
}
31+
32+
@Reducer
33+
private struct Feature {
34+
struct State: Equatable {
35+
var value = 0
36+
}
37+
enum Action {
38+
case response(Int)
39+
case start
40+
case stop
41+
}
42+
enum CancelID { case longLiving }
43+
var body: some ReducerOf<Self> {
44+
Reduce { state, action in
45+
switch action {
46+
case .response(let value):
47+
state.value = value
48+
return .none
49+
case .start:
50+
return .run { send in
51+
await send(.response(42))
52+
try await Task.never()
53+
}
54+
.cancellable(id: CancelID.longLiving, cancelInFlight: true)
55+
case .stop:
56+
return .cancel(id: CancelID.longLiving)
57+
}
58+
}
59+
}
60+
}
61+
62+
#endif

Tests/ComposableArchitectureTests/EffectCancellationTests.swift

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ final class EffectCancellationTests: BaseTCATestCase {
1111
self.cancellables.removeAll()
1212
}
1313

14+
override func invokeTest() {
15+
withMainSerialExecutor {
16+
super.invokeTest()
17+
}
18+
}
19+
1420
func testCancellation() async {
1521
let values = LockIsolated<[Int]>([])
1622

0 commit comments

Comments
 (0)