Skip to content

Commit 345dd6e

Browse files
authored
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.
1 parent 76ae1e4 commit 345dd6e

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Tests/GRPCTests/AsyncAwaitSupport/AsyncClientTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class AsyncClientCancellationTests: GRPCTestCase {
4242
self.server = nil
4343
}
4444

45-
try self.group.syncShutdownGracefully()
45+
try await self.group.shutdownGracefully()
4646
self.group = nil
4747

4848
try await super.tearDown()

Tests/GRPCTests/GRPCNetworkFrameworkTests.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,20 @@ final class GRPCNetworkFrameworkTests: GRPCTestCase {
4646
.appendingPathComponent("bundle")
4747
.appendingPathExtension("p12")
4848

49-
override func setUp() {
50-
super.setUp()
49+
// Not really 'async' but there is no 'func setUp() throws' to override.
50+
override func setUp() async throws {
51+
try await super.setUp()
5152

5253
self.tsGroup = NIOTSEventLoopGroup(loopCount: 1)
5354
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
5455

55-
self.identity = try? self.loadIdentity()
56+
self.identity = try self.loadIdentity()
5657
XCTAssertNotNil(
5758
self.identity,
5859
"Unable to load identity from '\(GRPCNetworkFrameworkTests.p12bundleURL)'"
5960
)
6061

61-
self.pkcs12Bundle = try? NIOSSLPKCS12Bundle(
62+
self.pkcs12Bundle = try NIOSSLPKCS12Bundle(
6263
file: GRPCNetworkFrameworkTests.p12bundleURL.path,
6364
passphrase: "password".utf8
6465
)
@@ -70,10 +71,10 @@ final class GRPCNetworkFrameworkTests: GRPCTestCase {
7071
}
7172

7273
override func tearDown() {
73-
XCTAssertNoThrow(try self.client.close().wait())
74-
XCTAssertNoThrow(try self.server.close().wait())
75-
XCTAssertNoThrow(try self.group.syncShutdownGracefully())
76-
XCTAssertNoThrow(try self.tsGroup.syncShutdownGracefully())
74+
XCTAssertNoThrow(try self.client?.close().wait())
75+
XCTAssertNoThrow(try self.server?.close().wait())
76+
XCTAssertNoThrow(try self.group?.syncShutdownGracefully())
77+
XCTAssertNoThrow(try self.tsGroup?.syncShutdownGracefully())
7778
super.tearDown()
7879
}
7980

@@ -84,8 +85,13 @@ final class GRPCNetworkFrameworkTests: GRPCTestCase {
8485
var rawItems: CFArray?
8586
let status = SecPKCS12Import(data as CFData, options as CFDictionary, &rawItems)
8687

87-
guard status == errSecSuccess else {
88-
XCTFail("SecPKCS12Import failed with status \(status)")
88+
switch status {
89+
case errSecSuccess:
90+
()
91+
case errSecInteractionNotAllowed:
92+
throw XCTSkip("Unable to import PKCS12 bundle: no interaction allowed")
93+
default:
94+
XCTFail("SecPKCS12Import: failed with status \(status)")
8995
return nil
9096
}
9197

0 commit comments

Comments
 (0)