Jelajahi Sumber

This fixes the tests for me.

Daniel Alm 8 tahun lalu
induk
melakukan
63a52c86b5

+ 2 - 0
.gitignore

@@ -9,5 +9,7 @@ Plugin/protoc-*
 Plugin/swiftgrpc.log
 Plugin/echo.*.swift
 Examples/Echo/PackageManager/Echo
+Examples/Echo/PackageManager/test.out
+Examples/Echo/PackageManager/echo.pid
 SwiftGRPC.xcodeproj
 Package.resolved

+ 5 - 5
Examples/Echo/PackageManager/Makefile

@@ -4,11 +4,11 @@ all:
 	cp .build/release/Echo .
 
 test:	all
-	Echo serve & /bin/echo $$! > echo.pid
-	Echo get > test.out
-	Echo expand >> test.out
-	Echo collect >> test.out
-	Echo update >> test.out
+	./Echo serve & /bin/echo $$! > echo.pid
+	./Echo get > test.out
+	./Echo expand >> test.out
+	./Echo collect >> test.out
+	./Echo update >> test.out
 	kill -9 `cat echo.pid`
 	diff test.out test.gold
 	

+ 13 - 9
Examples/Echo/PackageManager/Sources/main.swift

@@ -60,25 +60,29 @@ Group {
              description: "Run an echo server.") { ssl, address, port in
     let sem = DispatchSemaphore(value: 0)
     let echoProvider = EchoProvider()
+    var echoServer: Echo_EchoServer?
     if ssl {
       print("starting secure server")
       let certificateURL = URL(fileURLWithPath: "ssl.crt")
       let keyURL = URL(fileURLWithPath: "ssl.key")
-      if let echoServer = Echo_EchoServer(address: address + ":" + port,
-                                          certificateURL: certificateURL,
-                                          keyURL: keyURL,
-                                          provider: echoProvider) {
-        echoServer.start()
-      }
+      echoServer = Echo_EchoServer(address: address + ":" + port,
+                                   certificateURL: certificateURL,
+                                   keyURL: keyURL,
+                                   provider: echoProvider)
+      echoServer?.start()
     } else {
       print("starting insecure server")
-      let echoServer = Echo_EchoServer(address: address + ":" + port,
-                                       provider: echoProvider)
-      echoServer.start()
+      echoServer = Echo_EchoServer(address: address + ":" + port,
+                                   provider: echoProvider)
+      echoServer?.start()
     }
     // This blocks to keep the main thread from finishing while the server runs,
     // but the server never exits. Kill the process to stop it.
     _ = sem.wait(timeout: DispatchTime.distantFuture)
+    // This suppresses a "variable echoServer was written to, but never read" warning.
+    _ = echoServer
+    // And this ensures that echoServer doesn't get deallocated right after it is created.
+    echoServer = nil
   }
 
   $0.command("get", sslFlag, addressOption("localhost"), portOption, messageOption,