2
0

InteroperabilityTestCase.swift 4.7 KB

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