InteroperabilityTestCase.swift 5.8 KB

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