Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Nov 15, 2024
1 parent 72a53ec commit 155efa2
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions Tests/ComposableArchitectureTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1176,50 +1176,52 @@ final class StoreTests: BaseTCATestCase {
}
}

@Suite
struct ModernStoreTests {
@Reducer
fileprivate struct TaskTreeFeature {
let clock: TestClock<Duration>
@ObservableState
struct State { var count = 0 }
enum Action { case tap, response1, response2 }
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .tap:
return Effect.run { send in
await send(.response1)
}
case .response1:
state.count = 42
return Effect.run { send in
try await clock.sleep(for: .seconds(1))
await send(.response2)
#if canImport(Testing)
@Suite
struct ModernStoreTests {
@Reducer
fileprivate struct TaskTreeFeature {
let clock: TestClock<Duration>
@ObservableState
struct State { var count = 0 }
enum Action { case tap, response1, response2 }
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .tap:
return Effect.run { send in
await send(.response1)
}
case .response1:
state.count = 42
return Effect.run { send in
try await clock.sleep(for: .seconds(1))
await send(.response2)
}
case .response2:
state.count = 1729
return .none
}
case .response2:
state.count = 1729
return .none
}
}
}
}

@MainActor
@Test
func cancellation() async throws {
let clock = TestClock()
let store = Store(initialState: TaskTreeFeature.State()) { TaskTreeFeature(clock: clock) }
let task = store.send(.tap)
try await Task.sleep(for: .seconds(0.1))
#expect(store.count == 42)
task.cancel()
await clock.run()
withKnownIssue("Cancelling the root effect should not cancel the child effects.") {
#expect(store.count == 1729)
@MainActor
@Test
func cancellation() async throws {
let clock = TestClock()
let store = Store(initialState: TaskTreeFeature.State()) { TaskTreeFeature(clock: clock) }
let task = store.send(.tap)
try await Task.sleep(for: .seconds(0.1))
#expect(store.count == 42)
task.cancel()
await clock.run()
withKnownIssue("Cancelling the root effect should not cancel the child effects.") {
#expect(store.count == 1729)
}
}
}
}
#endif

private struct Count: TestDependencyKey {
var value: Int
Expand Down

0 comments on commit 155efa2

Please sign in to comment.