Browse Source

Allow network framework tests to be skipped when no user interaction (#1602)

Motivation:

The network framework tests require user interaction on their first run.
This is not possible in CI so skip the tests in those situations.

Modifications:

- Allow network framework tests to be skipped if import the pkcs12
  bundle fails with 'errSecInteractionNotAllowed'.

Result:

Fewer test failures.
George Barnett 2 years ago
parent
commit
345dd6e5eb

+ 1 - 1
Tests/GRPCTests/AsyncAwaitSupport/AsyncClientTests.swift

@@ -42,7 +42,7 @@ final class AsyncClientCancellationTests: GRPCTestCase {
       self.server = nil
     }
 
-    try self.group.syncShutdownGracefully()
+    try await self.group.shutdownGracefully()
     self.group = nil
 
     try await super.tearDown()

+ 16 - 10
Tests/GRPCTests/GRPCNetworkFrameworkTests.swift

@@ -46,19 +46,20 @@ final class GRPCNetworkFrameworkTests: GRPCTestCase {
     .appendingPathComponent("bundle")
     .appendingPathExtension("p12")
 
-  override func setUp() {
-    super.setUp()
+  // Not really 'async' but there is no 'func setUp() throws' to override.
+  override func setUp() async throws {
+    try await super.setUp()
 
     self.tsGroup = NIOTSEventLoopGroup(loopCount: 1)
     self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
 
-    self.identity = try? self.loadIdentity()
+    self.identity = try self.loadIdentity()
     XCTAssertNotNil(
       self.identity,
       "Unable to load identity from '\(GRPCNetworkFrameworkTests.p12bundleURL)'"
     )
 
-    self.pkcs12Bundle = try? NIOSSLPKCS12Bundle(
+    self.pkcs12Bundle = try NIOSSLPKCS12Bundle(
       file: GRPCNetworkFrameworkTests.p12bundleURL.path,
       passphrase: "password".utf8
     )
@@ -70,10 +71,10 @@ final class GRPCNetworkFrameworkTests: GRPCTestCase {
   }
 
   override func tearDown() {
-    XCTAssertNoThrow(try self.client.close().wait())
-    XCTAssertNoThrow(try self.server.close().wait())
-    XCTAssertNoThrow(try self.group.syncShutdownGracefully())
-    XCTAssertNoThrow(try self.tsGroup.syncShutdownGracefully())
+    XCTAssertNoThrow(try self.client?.close().wait())
+    XCTAssertNoThrow(try self.server?.close().wait())
+    XCTAssertNoThrow(try self.group?.syncShutdownGracefully())
+    XCTAssertNoThrow(try self.tsGroup?.syncShutdownGracefully())
     super.tearDown()
   }
 
@@ -84,8 +85,13 @@ final class GRPCNetworkFrameworkTests: GRPCTestCase {
     var rawItems: CFArray?
     let status = SecPKCS12Import(data as CFData, options as CFDictionary, &rawItems)
 
-    guard status == errSecSuccess else {
-      XCTFail("SecPKCS12Import failed with status \(status)")
+    switch status {
+    case errSecSuccess:
+      ()
+    case errSecInteractionNotAllowed:
+      throw XCTSkip("Unable to import PKCS12 bundle: no interaction allowed")
+    default:
+      XCTFail("SecPKCS12Import: failed with status \(status)")
       return nil
     }