Skip to content

Commit 4489716

Browse files
Fix race condition
1 parent e4914eb commit 4489716

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Sources/SwiftGRPC/Core/Call.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public struct CallResult: CustomStringConvertible {
108108
initialMetadata = op.receivedInitialMetadata()
109109
trailingMetadata = op.receivedTrailingMetadata()
110110
} else {
111-
statusCode = .ok
111+
statusCode = .unknown
112112
statusMessage = nil
113113
resultData = nil
114114
initialMetadata = nil

Tests/SwiftGRPCTests/GRPCTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ func callServerStream(channel: Channel) throws {
220220
sem.signal() // signal call is finished
221221
}
222222

223-
call.messageQueueEmpty.wait() // wait for start to finish
224-
225223
for _ in 0..<steps {
226224
let messageSem = DispatchSemaphore(value: 0)
227225
try call.receiveMessage(completion: { (data) in
@@ -234,6 +232,7 @@ func callServerStream(channel: Channel) throws {
234232

235233
_ = messageSem.wait()
236234
}
235+
237236
_ = sem.wait()
238237
}
239238

@@ -260,8 +259,6 @@ func callBiDiStream(channel: Channel) throws {
260259
sem.signal() // signal call is finished
261260
}
262261

263-
call.messageQueueEmpty.wait() // wait for start to finish
264-
265262
// Send pings
266263
for _ in 0..<steps {
267264
let pingSem = DispatchSemaphore(value: 0)
@@ -285,6 +282,8 @@ func callBiDiStream(channel: Channel) throws {
285282
})
286283
_ = pongSem.wait()
287284
}
285+
286+
_ = sem.wait()
288287
}
289288

290289
func runServer(server: Server) throws {

0 commit comments

Comments
 (0)