Skip to content

Commit 23b92fc

Browse files
stephencelismluisbrown
authored andcommitted
Only run flakey test locally and on macOS
(cherry picked from commit d6ecd69295698617b9ff855918d80bc9ea8b6c76) # Conflicts: # Tests/ComposableArchitectureTests/RuntimeWarningTests.swift
1 parent e488b60 commit 23b92fc

File tree

2 files changed

+98
-93
lines changed

2 files changed

+98
-93
lines changed

Examples/VoiceMemos/VoiceMemos/VoiceMemos.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AVFoundation
22
import ComposableArchitecture
3-
import IdentifiedCollections
43
import Foundation
4+
import IdentifiedCollections
55
import ReactiveSwift
66
import SwiftUI
77

@@ -48,21 +48,21 @@ let voiceMemosReducer = Reducer<VoiceMemosState, VoiceMemosAction, VoiceMemosEnv
4848
),
4949
voiceMemoReducer
5050
.forEach(
51-
state: \.voiceMemos,
52-
action: /VoiceMemosAction.voiceMemo(id:action:),
53-
environment: {
54-
VoiceMemoEnvironment(audioPlayerClient: $0.audioPlayer, mainRunLoop: $0.mainRunLoop)
55-
}
56-
),
51+
state: \.voiceMemos,
52+
action: /VoiceMemosAction.voiceMemo(id:action:),
53+
environment: {
54+
VoiceMemoEnvironment(audioPlayerClient: $0.audioPlayer, mainRunLoop: $0.mainRunLoop)
55+
}
56+
),
5757
Reducer { state, action, environment in
5858
var newRecordingMemo: RecordingMemoState {
5959
RecordingMemoState(
6060
date: environment.mainRunLoop.now.date,
6161
url: environment.temporaryDirectory()
62-
.appendingPathComponent(environment.uuid().uuidString)
63-
.appendingPathExtension("m4a")
64-
)
65-
}
62+
.appendingPathComponent(environment.uuid().uuidString)
63+
.appendingPathExtension("m4a")
64+
)
65+
}
6666

6767
switch action {
6868
case .alertDismissed:
@@ -88,7 +88,7 @@ let voiceMemosReducer = Reducer<VoiceMemosState, VoiceMemosAction, VoiceMemosEnv
8888
case .allowed:
8989
state.recordingMemo = newRecordingMemo
9090
return .none
91-
}
91+
}
9292

9393
case let .recordingMemo(.delegate(.didFinish(.success(recordingMemo)))):
9494
state.recordingMemo = nil
@@ -100,7 +100,7 @@ let voiceMemosReducer = Reducer<VoiceMemosState, VoiceMemosAction, VoiceMemosEnv
100100
),
101101
at: 0
102102
)
103-
return .none
103+
return .none
104104

105105
case .recordingMemo(.delegate(.didFinish(.failure))):
106106
state.alert = AlertState(title: TextState("Voice memo recording failed."))
@@ -192,28 +192,28 @@ struct RecordButton: View {
192192
let settingsAction: () -> Void
193193

194194
var body: some View {
195-
ZStack {
195+
ZStack {
196196
Group {
197-
Circle()
198-
.foregroundColor(Color(.label))
199-
.frame(width: 74, height: 74)
197+
Circle()
198+
.foregroundColor(Color(.label))
199+
.frame(width: 74, height: 74)
200200

201201
Button(action: self.action) {
202202
RoundedRectangle(cornerRadius: 35)
203-
.foregroundColor(Color(.systemRed))
203+
.foregroundColor(Color(.systemRed))
204204
.padding(2)
205-
}
206-
.frame(width: 70, height: 70)
205+
}
206+
.frame(width: 70, height: 70)
207207
}
208208
.opacity(self.permission == .denied ? 0.1 : 1)
209209

210210
if self.permission == .denied {
211-
VStack(spacing: 10) {
212-
Text("Recording requires microphone access.")
213-
.multilineTextAlignment(.center)
211+
VStack(spacing: 10) {
212+
Text("Recording requires microphone access.")
213+
.multilineTextAlignment(.center)
214214
Button("Open Settings", action: self.settingsAction)
215-
}
216-
.frame(maxWidth: .infinity, maxHeight: 74)
215+
}
216+
.frame(maxWidth: .infinity, maxHeight: 74)
217217
}
218218
}
219219
}

Tests/ComposableArchitectureTests/RuntimeWarningTests.swift

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -120,76 +120,81 @@ import XCTest
120120
_ = XCTWaiter.wait(for: [.init()], timeout: 2)
121121
}
122122

123-
@MainActor
124-
func testEffectEmitMainThread() async throws {
125-
try XCTSkipIf(ProcessInfo.processInfo.environment["CI"] != nil)
126-
XCTExpectFailure {
127-
[
128-
"""
129-
An effect completed on a non-main thread. …
130-
131-
Effect returned from:
132-
Action.response
133-
134-
Make sure to use ".receive(on:)" on any effects that execute on background threads to \
135-
receive their output on the main thread.
136-
137-
The "Store" class is not thread-safe, and so all interactions with an instance of "Store" \
138-
(including all of its scopes and derived view stores) must be done on the main thread.
139-
""",
140-
"""
141-
An effect completed on a non-main thread. …
142-
143-
Effect returned from:
144-
Action.tap
145-
146-
Make sure to use ".receive(on:)" on any effects that execute on background threads to \
147-
receive their output on the main thread.
148-
149-
The "Store" class is not thread-safe, and so all interactions with an instance of "Store" \
150-
(including all of its scopes and derived view stores) must be done on the main thread.
151-
""",
152-
"""
153-
An effect published an action on a non-main thread. …
154-
155-
Effect published:
156-
Action.response
157-
158-
Effect returned from:
159-
Action.tap
160-
161-
Make sure to use ".receive(on:)" on any effects that execute on background threads to \
162-
receive their output on the main thread.
163-
164-
The "Store" class is not thread-safe, and so all interactions with an instance of "Store" \
165-
(including all of its scopes and derived view stores) must be done on the main thread.
166-
""",
167-
]
168-
.contains($0.compactDescription)
169-
}
170-
171-
enum Action { case tap, response }
172-
let store = Store(
173-
initialState: 0,
174-
reducer: Reducer<Int, Action, Void> { state, action, _ in
175-
switch action {
176-
case .tap:
177-
return .run { observer in
178-
Thread.detachNewThread {
179-
XCTAssertFalse(Thread.isMainThread, "Effect should send on non-main thread.")
180-
observer.send(value: .response)
181-
observer.sendCompleted()
123+
#if os(macOS)
124+
@MainActor
125+
func testEffectEmitMainThread() async throws {
126+
try XCTSkipIf(ProcessInfo.processInfo.environment["CI"] != nil)
127+
XCTExpectFailure {
128+
[
129+
"""
130+
An effect completed on a non-main thread. …
131+
132+
Effect returned from:
133+
Action.response
134+
135+
Make sure to use ".receive(on:)" on any effects that execute on background threads to \
136+
receive their output on the main thread.
137+
138+
The "Store" class is not thread-safe, and so all interactions with an instance of \
139+
"Store" (including all of its scopes and derived view stores) must be done on the main \
140+
thread.
141+
""",
142+
"""
143+
An effect completed on a non-main thread. …
144+
145+
Effect returned from:
146+
Action.tap
147+
148+
Make sure to use ".receive(on:)" on any effects that execute on background threads to \
149+
receive their output on the main thread.
150+
151+
The "Store" class is not thread-safe, and so all interactions with an instance of \
152+
"Store" (including all of its scopes and derived view stores) must be done on the main \
153+
thread.
154+
""",
155+
"""
156+
An effect published an action on a non-main thread. …
157+
158+
Effect published:
159+
Action.response
160+
161+
Effect returned from:
162+
Action.tap
163+
164+
Make sure to use ".receive(on:)" on any effects that execute on background threads to \
165+
receive their output on the main thread.
166+
167+
The "Store" class is not thread-safe, and so all interactions with an instance of \
168+
"Store" (including all of its scopes and derived view stores) must be done on the main \
169+
thread.
170+
""",
171+
]
172+
.contains($0.compactDescription)
173+
}
174+
175+
enum Action { case tap, response }
176+
let store = Store(
177+
initialState: 0,
178+
reducer: Reducer<Int, Action, Void> { state, action, _ in
179+
switch action {
180+
case .tap:
181+
return .run { observer in
182+
Thread.detachNewThread {
183+
XCTAssertFalse(Thread.isMainThread, "Effect should send on non-main thread.")
184+
observer.send(value: .response)
185+
observer.sendCompleted()
186+
}
187+
return AnyDisposable {}
182188
}
183-
return AnyDisposable {}
189+
case .response:
190+
return .none
184191
}
185-
case .response:
186-
return .none
187-
}
188-
},
189-
environment: ()
190-
)
191-
await ViewStore(store).send(.tap).finish()
192-
}
192+
},
193+
environment: ()
194+
)
195+
await ViewStore(store).send(.tap).finish()
196+
}
197+
#endif
193198

194199
func testBindingUnhandledAction() {
195200
struct State: Equatable {

0 commit comments

Comments
 (0)