@@ -178,33 +178,47 @@ class GRPCAsyncClientCallTests: GRPCTestCase {
178
178
179
179
await assertThat ( try await update. initialMetadata, . is( . equalTo( Self . OKInitialMetadata) ) )
180
180
181
- actor TestResults {
182
- static var numResponses = 0
183
- static var numRequests = 0
184
- }
181
+ let counter = RequestResponseCounter ( )
185
182
186
183
// Send the requests and get responses in separate concurrent tasks and await the group.
187
184
_ = await withThrowingTaskGroup ( of: Void . self) { taskGroup in
188
185
// Send requests, then end, in a task.
189
186
taskGroup. addTask {
190
187
for word in [ " boyle " , " jeffers " , " holt " ] {
191
188
try await update. sendMessage ( . with { $0. text = word } )
192
- TestResults . numRequests += 1
189
+ await counter . incrementRequests ( )
193
190
}
194
191
try await update. sendEnd ( )
195
192
}
196
193
// Get responses in a separate task.
197
194
taskGroup. addTask {
198
195
for try await _ in update. responses {
199
- TestResults . numResponses += 1
196
+ await counter . incrementResponses ( )
200
197
}
201
198
}
202
199
}
203
- await assertThat ( TestResults . numRequests, . is( . equalTo( 3 ) ) )
204
- await assertThat ( TestResults . numResponses, . is( . equalTo( 3 ) ) )
200
+
201
+ await assertThat ( await counter. numRequests, . is( . equalTo( 3 ) ) )
202
+ await assertThat ( await counter. numResponses, . is( . equalTo( 3 ) ) )
205
203
await assertThat ( try await update. trailingMetadata, . is( . equalTo( Self . OKTrailingMetadata) ) )
206
204
await assertThat ( await update. status, . hasCode( . ok) )
207
205
} }
208
206
}
209
207
208
+ // Workaround https://bugs.swift.org/browse/SR-15070 (compiler crashes when defining a class/actor
209
+ // in an async context).
210
+ @available ( macOS 12 , iOS 15 , tvOS 15 , watchOS 8 , * )
211
+ fileprivate actor RequestResponseCounter {
212
+ var numResponses = 0
213
+ var numRequests = 0
214
+
215
+ func incrementResponses( ) async {
216
+ self . numResponses += 1
217
+ }
218
+
219
+ func incrementRequests( ) async {
220
+ self . numRequests += 1
221
+ }
222
+ }
223
+
210
224
#endif
0 commit comments