PlatformSupportTests.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import Foundation
  2. import GRPC
  3. import NIO
  4. import NIOTransportServices
  5. import XCTest
  6. class PlatformSupportTests: GRPCTestCase {
  7. var group: EventLoopGroup!
  8. override func tearDown() {
  9. XCTAssertNoThrow(try self.group?.syncShutdownGracefully())
  10. }
  11. func testMakeEventLoopGroupReturnsMultiThreadedGroupForPosix() {
  12. self.group = PlatformSupport.makeEventLoopGroup(
  13. loopCount: 1,
  14. networkPreference: .userDefined(.posix)
  15. )
  16. XCTAssertTrue(self.group is MultiThreadedEventLoopGroup)
  17. }
  18. func testMakeEventLoopGroupReturnsNIOTSGroupForNetworkFramework() {
  19. // If we don't have Network.framework then we can't test this.
  20. #if canImport(Network)
  21. guard #available(macOS 10.14, *) else { return }
  22. self.group = PlatformSupport.makeEventLoopGroup(
  23. loopCount: 1,
  24. networkPreference: .userDefined(.networkFramework)
  25. )
  26. XCTAssertTrue(self.group is NIOTSEventLoopGroup)
  27. #endif
  28. }
  29. func testMakeClientBootstrapReturnsClientBootstrapForMultiThreadedGroup() {
  30. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  31. let bootstrap = PlatformSupport.makeClientBootstrap(group: self.group)
  32. XCTAssertTrue(bootstrap is ClientBootstrap)
  33. }
  34. func testMakeClientBootstrapReturnsClientBootstrapForEventLoop() {
  35. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  36. let eventLoop = self.group.next()
  37. let bootstrap = PlatformSupport.makeClientBootstrap(group: eventLoop)
  38. XCTAssertTrue(bootstrap is ClientBootstrap)
  39. }
  40. func testMakeClientBootstrapReturnsNIOTSConnectionBootstrapForNIOTSGroup() {
  41. // If we don't have Network.framework then we can't test this.
  42. #if canImport(Network)
  43. guard #available(macOS 10.14, *) else { return }
  44. self.group = NIOTSEventLoopGroup(loopCount: 1)
  45. let bootstrap = PlatformSupport.makeClientBootstrap(group: self.group)
  46. XCTAssertTrue(bootstrap is NIOTSConnectionBootstrap)
  47. #endif
  48. }
  49. func testMakeClientBootstrapReturnsNIOTSConnectionBootstrapForQoSEventLoop() {
  50. // If we don't have Network.framework then we can't test this.
  51. #if canImport(Network)
  52. guard #available(macOS 10.14, *) else { return }
  53. self.group = NIOTSEventLoopGroup(loopCount: 1)
  54. let eventLoop = self.group.next()
  55. XCTAssertTrue(eventLoop is QoSEventLoop)
  56. let bootstrap = PlatformSupport.makeClientBootstrap(group: eventLoop)
  57. XCTAssertTrue(bootstrap is NIOTSConnectionBootstrap)
  58. #endif
  59. }
  60. func testMakeServerBootstrapReturnsServerBootstrapForMultiThreadedGroup() {
  61. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  62. let bootstrap = PlatformSupport.makeServerBootstrap(group: self.group)
  63. XCTAssertTrue(bootstrap is ServerBootstrap)
  64. }
  65. func testMakeServerBootstrapReturnsServerBootstrapForEventLoop() {
  66. self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
  67. let eventLoop = self.group.next()
  68. let bootstrap = PlatformSupport.makeServerBootstrap(group: eventLoop)
  69. XCTAssertTrue(bootstrap is ServerBootstrap)
  70. }
  71. func testMakeServerBootstrapReturnsNIOTSListenerBootstrapForNIOTSGroup() {
  72. // If we don't have Network.framework then we can't test this.
  73. #if canImport(Network)
  74. guard #available(macOS 10.14, *) else { return }
  75. self.group = NIOTSEventLoopGroup(loopCount: 1)
  76. let bootstrap = PlatformSupport.makeServerBootstrap(group: self.group)
  77. XCTAssertTrue(bootstrap is NIOTSListenerBootstrap)
  78. #endif
  79. }
  80. func testMakeServerBootstrapReturnsNIOTSListenerBootstrapForQoSEventLoop() {
  81. // If we don't have Network.framework then we can't test this.
  82. #if canImport(Network)
  83. guard #available(macOS 10.14, *) else { return }
  84. self.group = NIOTSEventLoopGroup(loopCount: 1)
  85. let eventLoop = self.group.next()
  86. XCTAssertTrue(eventLoop is QoSEventLoop)
  87. let bootstrap = PlatformSupport.makeServerBootstrap(group: eventLoop)
  88. XCTAssertTrue(bootstrap is NIOTSListenerBootstrap)
  89. #endif
  90. }
  91. }