PlatformSupportTests.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2019, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. import GRPC
  18. import NIO
  19. import NIOTransportServices
  20. import XCTest
  21. class PlatformSupportTests: GRPCTestCase {
  22. var group: EventLoopGroup!
  23. override func tearDown() {
  24. XCTAssertNoThrow(try self.group?.syncShutdownGracefully())
  25. }
  26. func testMakeEventLoopGroupReturnsMultiThreadedGroupForPosix() {
  27. self.group = PlatformSupport.makeEventLoopGroup(
  28. loopCount: 1,
  29. networkPreference: .userDefined(.posix)
  30. )
  31. XCTAssertTrue(self.group is MultiThreadedEventLoopGroup)
  32. }
  33. func testMakeEventLoopGroupReturnsNIOTSGroupForNetworkFramework() {
  34. // If we don't have Network.framework then we can't test this.
  35. #if canImport(Network)
  36. guard #available(macOS 10.14, *) else { return }
  37. self.group = PlatformSupport.makeEventLoopGroup(
  38. loopCount: 1,
  39. networkPreference: .userDefined(.networkFramework)
  40. )
  41. XCTAssertTrue(self.group is NIOTSEventLoopGroup)
  42. #endif
  43. }
  44. func testMakeClientBootstrapReturnsClientBootstrapForMultiThreadedGroup() {
  45. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  46. let bootstrap = PlatformSupport.makeClientBootstrap(group: self.group)
  47. XCTAssertTrue(bootstrap is ClientBootstrap)
  48. }
  49. func testMakeClientBootstrapReturnsClientBootstrapForEventLoop() {
  50. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  51. let eventLoop = self.group.next()
  52. let bootstrap = PlatformSupport.makeClientBootstrap(group: eventLoop)
  53. XCTAssertTrue(bootstrap is ClientBootstrap)
  54. }
  55. func testMakeClientBootstrapReturnsNIOTSConnectionBootstrapForNIOTSGroup() {
  56. // If we don't have Network.framework then we can't test this.
  57. #if canImport(Network)
  58. guard #available(macOS 10.14, *) else { return }
  59. self.group = NIOTSEventLoopGroup(loopCount: 1)
  60. let bootstrap = PlatformSupport.makeClientBootstrap(group: self.group)
  61. XCTAssertTrue(bootstrap is NIOTSConnectionBootstrap)
  62. #endif
  63. }
  64. func testMakeClientBootstrapReturnsNIOTSConnectionBootstrapForQoSEventLoop() {
  65. // If we don't have Network.framework then we can't test this.
  66. #if canImport(Network)
  67. guard #available(macOS 10.14, *) else { return }
  68. self.group = NIOTSEventLoopGroup(loopCount: 1)
  69. let eventLoop = self.group.next()
  70. XCTAssertTrue(eventLoop is QoSEventLoop)
  71. let bootstrap = PlatformSupport.makeClientBootstrap(group: eventLoop)
  72. XCTAssertTrue(bootstrap is NIOTSConnectionBootstrap)
  73. #endif
  74. }
  75. func testMakeServerBootstrapReturnsServerBootstrapForMultiThreadedGroup() {
  76. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  77. let bootstrap = PlatformSupport.makeServerBootstrap(group: self.group)
  78. XCTAssertTrue(bootstrap is ServerBootstrap)
  79. }
  80. func testMakeServerBootstrapReturnsServerBootstrapForEventLoop() {
  81. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  82. let eventLoop = self.group.next()
  83. let bootstrap = PlatformSupport.makeServerBootstrap(group: eventLoop)
  84. XCTAssertTrue(bootstrap is ServerBootstrap)
  85. }
  86. func testMakeServerBootstrapReturnsNIOTSListenerBootstrapForNIOTSGroup() {
  87. // If we don't have Network.framework then we can't test this.
  88. #if canImport(Network)
  89. guard #available(macOS 10.14, *) else { return }
  90. self.group = NIOTSEventLoopGroup(loopCount: 1)
  91. let bootstrap = PlatformSupport.makeServerBootstrap(group: self.group)
  92. XCTAssertTrue(bootstrap is NIOTSListenerBootstrap)
  93. #endif
  94. }
  95. func testMakeServerBootstrapReturnsNIOTSListenerBootstrapForQoSEventLoop() {
  96. // If we don't have Network.framework then we can't test this.
  97. #if canImport(Network)
  98. guard #available(macOS 10.14, *) else { return }
  99. self.group = NIOTSEventLoopGroup(loopCount: 1)
  100. let eventLoop = self.group.next()
  101. XCTAssertTrue(eventLoop is QoSEventLoop)
  102. let bootstrap = PlatformSupport.makeServerBootstrap(group: eventLoop)
  103. XCTAssertTrue(bootstrap is NIOTSListenerBootstrap)
  104. #endif
  105. }
  106. }