-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03ad0cc
commit 8013f1a
Showing
1 changed file
with
48 additions
and
48 deletions.
There are no files selected for viewing
96 changes: 48 additions & 48 deletions
96
Tests/ComposableArchitectureTests/EffectCancellationIsolationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
#if canImport(Testing) | ||
import ComposableArchitecture | ||
import Testing | ||
import ComposableArchitecture | ||
import Testing | ||
|
||
@Suite | ||
struct EffectCancellationIsolationTests { | ||
@Test | ||
func testIsolation1() async { | ||
let store = await TestStore(initialState: Feature.State()) { | ||
Feature() | ||
@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) | ||
} | ||
await store.send(.start) | ||
await store.receive(\.response) { | ||
$0.value = 42 | ||
|
||
@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) | ||
} | ||
await store.send(.stop) | ||
} | ||
|
||
@Test | ||
func testIsolation2() async { | ||
let store = await TestStore(initialState: Feature.State()) { | ||
Feature() | ||
@Reducer | ||
private struct Feature { | ||
struct State: Equatable { | ||
var value = 0 | ||
} | ||
await store.send(.start) | ||
await store.receive(\.response) { | ||
$0.value = 42 | ||
enum Action { | ||
case response(Int) | ||
case start | ||
case stop | ||
} | ||
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() | ||
} | ||
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) | ||
case .stop: | ||
return .cancel(id: CancelID.longLiving) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |