ソースを参照

"Fix" GRPCTests again by inserting a small delay in between sends. We really don't want to need such delays, so this is only a temporary fix until I finally find the proper underlying cause.

Daniel Alm 7 年 前
コミット
7ed242e571

+ 4 - 4
Sources/SwiftGRPC/Core/CallResult.swift

@@ -42,20 +42,20 @@ public struct CallResult: CustomStringConvertible {
   }
   
   public var description: String {
-    var result = "status \(statusCode)"
+    var result = "\(success ? "successful" : "unsuccessful"), status \(statusCode)"
     if let statusMessage = self.statusMessage {
       result += ": " + statusMessage
     }
     if let resultData = self.resultData {
-      result += "\n"
+      result += "\nresultData: "
       result += resultData.description
     }
     if let initialMetadata = self.initialMetadata {
-      result += "\n"
+      result += "\ninitialMetadata: "
       result += initialMetadata.description
     }
     if let trailingMetadata = self.trailingMetadata {
-      result += "\n"
+      result += "\ntrailingMetadata: "
       result += trailingMetadata.description
     }
     return result

+ 10 - 9
Tests/SwiftGRPCTests/GRPCTests.swift

@@ -69,7 +69,7 @@ let trailingServerMetadata =
     "11": "eleven",
     "12": "twelve"
 ]
-let steps = 10
+let steps = 100
 let hello = "/hello.unary"
 let helloServerStream = "/hello.server-stream"
 let helloBiDiStream = "/hello.bidi-stream"
@@ -133,13 +133,9 @@ func runClient(useSSL: Bool) throws {
   let channel: Channel
 
   if useSSL {
-    let certificateURL = URL(fileURLWithPath: "Tests/ssl.crt")
-    guard
-      let certificates = try? String(contentsOf: certificateURL, encoding: .utf8)
-      else {
-        return
-    }
-    channel = Channel(address: address, certificates: certificates, host: host)
+    channel = Channel(address: address,
+                      certificates: String(data: certificateForTests, encoding: .utf8)!,
+                      host: host)
   } else {
     channel = Channel(address: address, secure: false)
   }
@@ -218,7 +214,6 @@ func callServerStream(channel: Channel) throws {
       }
       messageSem.signal()
     }
-
     _ = messageSem.wait()
   }
 
@@ -356,6 +351,9 @@ func handleServerStream(requestHandler: Handler) throws {
       XCTAssertNil(error)
     }
     requestHandler.call.messageQueueEmpty.wait()
+    // FIXME(danielalm): For some (so far unknown) reason, this delay is required to prevent some sent messages to get
+    // dropped, even though we already queue messages that can't be sent right now.
+    Thread.sleep(forTimeInterval: 0.0001)
   }
 
   let trailingMetadataToSend = Metadata(trailingServerMetadata)
@@ -395,6 +393,9 @@ func handleBiDiStream(requestHandler: Handler) throws {
       XCTAssertNil(error)
     }
     requestHandler.call.messageQueueEmpty.wait()
+    // FIXME(danielalm): For some (so far unknown) reason, this delay is required to prevent some sent messages to get
+    // dropped, even though we already queue messages that can't be sent right now.
+    Thread.sleep(forTimeInterval: 0.0001)
   }
 
   let trailingMetadataToSend = Metadata(trailingServerMetadata)