InteroperabilityTestCase.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 NIOHTTP1
  20. public protocol InteroperabilityTest {
  21. /// Run a test case using the given connection.
  22. ///
  23. /// The test case is considered unsuccessful if any exception is thrown, conversely if no
  24. /// exceptions are thrown it is successful.
  25. ///
  26. /// - Parameter connection: The connection to use for the test.
  27. /// - Throws: Any exception may be thrown to indicate an unsuccessful test.
  28. func run(using connection: ClientConnection) throws
  29. /// Configure the connection from a set of defaults using to run the entire suite.
  30. ///
  31. /// Test cases may use this to, for example, enable compression at the connection level on a
  32. /// per-test basis.
  33. ///
  34. /// - Parameter defaults: The default configuration for the test run.
  35. func configure(builder: ClientConnection.Builder)
  36. }
  37. extension InteroperabilityTest {
  38. func configure(builder: ClientConnection.Builder) {}
  39. }
  40. /// Test cases as listed by the [gRPC interoperability test description
  41. /// specification](https://github.com/grpc/grpc/blob/master/doc/interop-test-descriptions.md).
  42. ///
  43. /// This is not a complete list, the following tests have not been implemented:
  44. /// - compute_engine_creds
  45. /// - jwt_token_creds
  46. /// - oauth2_auth_token
  47. /// - per_rpc_creds
  48. /// - google_default_credentials
  49. /// - compute_engine_channel_credentials
  50. ///
  51. /// Note: a description from the specification is included inline for each test as documentation for
  52. /// its associated `InteroperabilityTest` class.
  53. public enum InteroperabilityTestCase: String, CaseIterable {
  54. case emptyUnary = "empty_unary"
  55. case cacheableUnary = "cacheable_unary"
  56. case largeUnary = "large_unary"
  57. case clientCompressedUnary = "client_compressed_unary"
  58. case serverCompressedUnary = "server_compressed_unary"
  59. case clientStreaming = "client_streaming"
  60. case clientCompressedStreaming = "client_compressed_streaming"
  61. case serverStreaming = "server_streaming"
  62. case serverCompressedStreaming = "server_compressed_streaming"
  63. case pingPong = "ping_pong"
  64. case emptyStream = "empty_stream"
  65. case customMetadata = "custom_metadata"
  66. case statusCodeAndMessage = "status_code_and_message"
  67. case specialStatusMessage = "special_status_message"
  68. case unimplementedMethod = "unimplemented_method"
  69. case unimplementedService = "unimplemented_service"
  70. case cancelAfterBegin = "cancel_after_begin"
  71. case cancelAfterFirstResponse = "cancel_after_first_response"
  72. case timeoutOnSleepingServer = "timeout_on_sleeping_server"
  73. public var name: String {
  74. return self.rawValue
  75. }
  76. }
  77. extension InteroperabilityTestCase {
  78. /// Return a new instance of the test case.
  79. public func makeTest() -> InteroperabilityTest {
  80. switch self {
  81. case .emptyUnary:
  82. return EmptyUnary()
  83. case .cacheableUnary:
  84. return CacheableUnary()
  85. case .largeUnary:
  86. return LargeUnary()
  87. case .clientCompressedUnary:
  88. return ClientCompressedUnary()
  89. case .serverCompressedUnary:
  90. return ServerCompressedUnary()
  91. case .clientStreaming:
  92. return ClientStreaming()
  93. case .clientCompressedStreaming:
  94. return ClientCompressedStreaming()
  95. case .serverStreaming:
  96. return ServerStreaming()
  97. case .serverCompressedStreaming:
  98. return ServerCompressedStreaming()
  99. case .pingPong:
  100. return PingPong()
  101. case .emptyStream:
  102. return EmptyStream()
  103. case .customMetadata:
  104. return CustomMetadata()
  105. case .statusCodeAndMessage:
  106. return StatusCodeAndMessage()
  107. case .specialStatusMessage:
  108. return SpecialStatusMessage()
  109. case .unimplementedMethod:
  110. return UnimplementedMethod()
  111. case .unimplementedService:
  112. return UnimplementedService()
  113. case .cancelAfterBegin:
  114. return CancelAfterBegin()
  115. case .cancelAfterFirstResponse:
  116. return CancelAfterFirstResponse()
  117. case .timeoutOnSleepingServer:
  118. return TimeoutOnSleepingServer()
  119. }
  120. }
  121. /// The set of server features required to run this test.
  122. public var requiredServerFeatures: Set<ServerFeature> {
  123. switch self {
  124. case .emptyUnary:
  125. return [.emptyCall]
  126. case .cacheableUnary:
  127. return [.cacheableUnaryCall]
  128. case .largeUnary:
  129. return [.unaryCall]
  130. case .clientStreaming:
  131. return [.streamingInputCall]
  132. case .clientCompressedStreaming:
  133. return [.streamingInputCall, .compressedRequest]
  134. case .clientCompressedUnary:
  135. return [.unaryCall, .compressedRequest]
  136. case .serverCompressedUnary:
  137. return [.unaryCall, .compressedResponse]
  138. case .serverStreaming:
  139. return [.streamingOutputCall]
  140. case .serverCompressedStreaming:
  141. return [.streamingOutputCall, .compressedResponse]
  142. case .pingPong:
  143. return [.fullDuplexCall]
  144. case .emptyStream:
  145. return [.fullDuplexCall]
  146. case .customMetadata:
  147. return [.unaryCall, .fullDuplexCall, .echoMetadata]
  148. case .statusCodeAndMessage:
  149. return [.unaryCall, .fullDuplexCall, .echoStatus]
  150. case .specialStatusMessage:
  151. return [.unaryCall, .echoStatus]
  152. case .unimplementedMethod:
  153. return []
  154. case .unimplementedService:
  155. return []
  156. case .cancelAfterBegin:
  157. return [.streamingInputCall]
  158. case .cancelAfterFirstResponse:
  159. return [.fullDuplexCall]
  160. case .timeoutOnSleepingServer:
  161. return [.fullDuplexCall]
  162. }
  163. }
  164. }