Skip to content

Commit 99f0f55

Browse files
mbrandonwmluisbrown
authored andcommitted
Make testMergeFuses more stable.
(cherry picked from commit 26dce235baf67931ff4bd255b9f31dbebaf26626) # Conflicts: # Tests/ComposableArchitectureTests/EffectOperationTests.swift
1 parent 39d60ac commit 99f0f55

File tree

1 file changed

+123
-123
lines changed

1 file changed

+123
-123
lines changed

Tests/ComposableArchitectureTests/EffectOperationTests.swift

Lines changed: 123 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -4,150 +4,150 @@ import XCTest
44

55
// `@MainActor` introduces issues gathering tests on Linux
66
#if !os(Linux)
7-
@MainActor
8-
class EffectOperationTests: XCTestCase {
9-
func testMergeDiscardsNones() async {
10-
var effect = Effect<Int, Never>.none
11-
.merge(with: .none)
12-
switch effect.operation {
13-
case .none:
14-
XCTAssertTrue(true)
15-
default:
16-
XCTFail()
17-
}
7+
@MainActor
8+
class EffectOperationTests: XCTestCase {
9+
func testMergeDiscardsNones() async {
10+
var effect = Effect<Int, Never>.none
11+
.merge(with: .none)
12+
switch effect.operation {
13+
case .none:
14+
XCTAssertTrue(true)
15+
default:
16+
XCTFail()
17+
}
1818

19-
effect = Effect<Int, Never>.task { 42 }
20-
.merge(with: .none)
21-
switch effect.operation {
22-
case let .run(_, send):
23-
await send(.init(send: { XCTAssertEqual($0, 42) }))
24-
default:
25-
XCTFail()
26-
}
19+
effect = Effect<Int, Never>.task { 42 }
20+
.merge(with: .none)
21+
switch effect.operation {
22+
case let .run(_, send):
23+
await send(.init(send: { XCTAssertEqual($0, 42) }))
24+
default:
25+
XCTFail()
26+
}
2727

28-
effect = Effect<Int, Never>.none
29-
.merge(with: .task { 42 })
30-
switch effect.operation {
31-
case let .run(_, send):
32-
await send(.init(send: { XCTAssertEqual($0, 42) }))
33-
default:
34-
XCTFail()
35-
}
28+
effect = Effect<Int, Never>.none
29+
.merge(with: .task { 42 })
30+
switch effect.operation {
31+
case let .run(_, send):
32+
await send(.init(send: { XCTAssertEqual($0, 42) }))
33+
default:
34+
XCTFail()
35+
}
3636

37-
effect = Effect<Int, Never>.run { await $0(42) }
38-
.merge(with: .none)
39-
switch effect.operation {
40-
case let .run(_, send):
41-
await send(.init(send: { XCTAssertEqual($0, 42) }))
42-
default:
43-
XCTFail()
44-
}
37+
effect = Effect<Int, Never>.run { await $0(42) }
38+
.merge(with: .none)
39+
switch effect.operation {
40+
case let .run(_, send):
41+
await send(.init(send: { XCTAssertEqual($0, 42) }))
42+
default:
43+
XCTFail()
44+
}
4545

46-
effect = Effect<Int, Never>.none
47-
.merge(with: .run { await $0(42) })
48-
switch effect.operation {
49-
case let .run(_, send):
50-
await send(.init(send: { XCTAssertEqual($0, 42) }))
51-
default:
52-
XCTFail()
53-
}
46+
effect = Effect<Int, Never>.none
47+
.merge(with: .run { await $0(42) })
48+
switch effect.operation {
49+
case let .run(_, send):
50+
await send(.init(send: { XCTAssertEqual($0, 42) }))
51+
default:
52+
XCTFail()
5453
}
54+
}
5555

56-
func testConcatenateDiscardsNones() async {
57-
var effect = Effect<Int, Never>.none
58-
.concatenate(with: .none)
59-
switch effect.operation {
60-
case .none:
61-
XCTAssertTrue(true)
62-
default:
63-
XCTFail()
64-
}
56+
func testConcatenateDiscardsNones() async {
57+
var effect = Effect<Int, Never>.none
58+
.concatenate(with: .none)
59+
switch effect.operation {
60+
case .none:
61+
XCTAssertTrue(true)
62+
default:
63+
XCTFail()
64+
}
6565

66-
effect = Effect<Int, Never>.task { 42 }
67-
.concatenate(with: .none)
68-
switch effect.operation {
69-
case let .run(_, send):
70-
await send(.init(send: { XCTAssertEqual($0, 42) }))
71-
default:
72-
XCTFail()
73-
}
66+
effect = Effect<Int, Never>.task { 42 }
67+
.concatenate(with: .none)
68+
switch effect.operation {
69+
case let .run(_, send):
70+
await send(.init(send: { XCTAssertEqual($0, 42) }))
71+
default:
72+
XCTFail()
73+
}
7474

75-
effect = Effect<Int, Never>.none
76-
.concatenate(with: .task { 42 })
77-
switch effect.operation {
78-
case let .run(_, send):
79-
await send(.init(send: { XCTAssertEqual($0, 42) }))
80-
default:
81-
XCTFail()
82-
}
75+
effect = Effect<Int, Never>.none
76+
.concatenate(with: .task { 42 })
77+
switch effect.operation {
78+
case let .run(_, send):
79+
await send(.init(send: { XCTAssertEqual($0, 42) }))
80+
default:
81+
XCTFail()
82+
}
8383

84-
effect = Effect<Int, Never>.run { await $0(42) }
85-
.concatenate(with: .none)
86-
switch effect.operation {
87-
case let .run(_, send):
88-
await send(.init(send: { XCTAssertEqual($0, 42) }))
89-
default:
90-
XCTFail()
91-
}
84+
effect = Effect<Int, Never>.run { await $0(42) }
85+
.concatenate(with: .none)
86+
switch effect.operation {
87+
case let .run(_, send):
88+
await send(.init(send: { XCTAssertEqual($0, 42) }))
89+
default:
90+
XCTFail()
91+
}
9292

93-
effect = Effect<Int, Never>.none
94-
.concatenate(with: .run { await $0(42) })
95-
switch effect.operation {
96-
case let .run(_, send):
97-
await send(.init(send: { XCTAssertEqual($0, 42) }))
98-
default:
99-
XCTFail()
100-
}
93+
effect = Effect<Int, Never>.none
94+
.concatenate(with: .run { await $0(42) })
95+
switch effect.operation {
96+
case let .run(_, send):
97+
await send(.init(send: { XCTAssertEqual($0, 42) }))
98+
default:
99+
XCTFail()
101100
}
101+
}
102102

103-
func testMergeFuses() async {
104-
var values = [Int]()
103+
func testMergeFuses() async {
104+
var values = [Int]()
105105

106-
let effect = Effect<Int, Never>.task {
107-
try await Task.sleep(nanoseconds: NSEC_PER_SEC / 10)
108-
return 42
109-
}
110-
.merge(
111-
with: .task {
112-
try await Task.sleep(nanoseconds: NSEC_PER_SEC / 5)
113-
return 1729
114-
}
115-
)
116-
switch effect.operation {
117-
case let .run(_, send):
118-
await send(.init(send: { values.append($0) }))
119-
default:
120-
XCTFail()
106+
let effect = Effect<Int, Never>.task {
107+
try await Task.sleep(nanoseconds: NSEC_PER_SEC / 10)
108+
return 42
109+
}
110+
.merge(
111+
with: .task {
112+
try await Task.sleep(nanoseconds: NSEC_PER_SEC / 2)
113+
return 1729
121114
}
122-
123-
XCTAssertEqual(values.sorted(), [42, 1729]) // merge is racy, hence the sorted()
115+
)
116+
switch effect.operation {
117+
case let .run(_, send):
118+
await send(.init(send: { values.append($0) }))
119+
default:
120+
XCTFail()
124121
}
125122

126-
func testConcatenateFuses() async {
127-
var values = [Int]()
123+
XCTAssertEqual(values.sorted(), [42, 1729]) // merge is racy, hence the sorted()
124+
}
128125

129-
let effect = Effect<Int, Never>.task { 42 }
130-
.concatenate(with: .task { 1729 })
131-
switch effect.operation {
132-
case let .run(_, send):
133-
await send(.init(send: { values.append($0) }))
134-
default:
135-
XCTFail()
136-
}
126+
func testConcatenateFuses() async {
127+
var values = [Int]()
137128

138-
XCTAssertEqual(values, [42, 1729])
129+
let effect = Effect<Int, Never>.task { 42 }
130+
.concatenate(with: .task { 1729 })
131+
switch effect.operation {
132+
case let .run(_, send):
133+
await send(.init(send: { values.append($0) }))
134+
default:
135+
XCTFail()
139136
}
140137

141-
func testMap() async {
142-
let effect = Effect<Int, Never>.task { 42 }
143-
.map { "\($0)" }
138+
XCTAssertEqual(values, [42, 1729])
139+
}
144140

145-
switch effect.operation {
146-
case let .run(_, send):
147-
await send(.init(send: { XCTAssertEqual($0, "42") }))
148-
default:
149-
XCTFail()
150-
}
141+
func testMap() async {
142+
let effect = Effect<Int, Never>.task { 42 }
143+
.map { "\($0)" }
144+
145+
switch effect.operation {
146+
case let .run(_, send):
147+
await send(.init(send: { XCTAssertEqual($0, "42") }))
148+
default:
149+
XCTFail()
151150
}
152151
}
152+
}
153153
#endif

0 commit comments

Comments
 (0)