InteroperabilityTestCase.swift 5.8 KB

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