|
|
@@ -65,13 +65,17 @@ open class ServerSessionBidirectionalStreamingBase<InputType: Message, OutputTyp
|
|
|
/// Simple fake implementation of ServerSessionBidirectionalStreaming that returns a previously-defined set of results
|
|
|
/// and stores sent values for later verification.
|
|
|
open class ServerSessionBidirectionalStreamingTestStub<InputType: Message, OutputType: Message>: ServerSessionTestStub, ServerSessionBidirectionalStreaming {
|
|
|
+ open var lock = Mutex()
|
|
|
+
|
|
|
open var inputs: [InputType] = []
|
|
|
open var outputs: [OutputType] = []
|
|
|
open var status: ServerStatus?
|
|
|
|
|
|
open func _receive(timeout: DispatchTime) throws -> InputType? {
|
|
|
- defer { if !inputs.isEmpty { inputs.removeFirst() } }
|
|
|
- return inputs.first
|
|
|
+ return lock.synchronize {
|
|
|
+ defer { if !inputs.isEmpty { inputs.removeFirst() } }
|
|
|
+ return inputs.first
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
open func receive(completion: @escaping (ResultOrRPCError<InputType?>) -> Void) throws {
|
|
|
@@ -79,15 +83,15 @@ open class ServerSessionBidirectionalStreamingTestStub<InputType: Message, Outpu
|
|
|
}
|
|
|
|
|
|
open func send(_ message: OutputType, completion _: @escaping (Error?) -> Void) throws {
|
|
|
- outputs.append(message)
|
|
|
+ lock.synchronize { outputs.append(message) }
|
|
|
}
|
|
|
|
|
|
open func _send(_ message: OutputType, timeout: DispatchTime) throws {
|
|
|
- outputs.append(message)
|
|
|
+ lock.synchronize { outputs.append(message) }
|
|
|
}
|
|
|
|
|
|
open func close(withStatus status: ServerStatus, completion: (() -> Void)?) throws {
|
|
|
- self.status = status
|
|
|
+ lock.synchronize { self.status = status }
|
|
|
completion?()
|
|
|
}
|
|
|
|