InteroperabilityTestCase.swift 5.9 KB

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