Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/GRPCTests/AsyncAwaitSupport/AsyncClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 16 additions & 10 deletions Tests/GRPCTests/GRPCNetworkFrameworkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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()
}

Expand All @@ -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
}

Expand Down