InProcessInteroperabilityTests.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2024, 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 GRPCCore
  17. import GRPCInProcessTransport
  18. import InteroperabilityTests
  19. import XCTest
  20. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  21. final class InProcessInteroperabilityTests: XCTestCase {
  22. func runInProcessTransport(
  23. interopTestCase: InteroperabilityTestCase
  24. ) async throws {
  25. do {
  26. let inProcess = InProcessTransport.makePair()
  27. try await withThrowingTaskGroup(of: Void.self) { group in
  28. group.addTask {
  29. let server = GRPCServer(transport: inProcess.server, services: [TestService()])
  30. try await server.serve()
  31. }
  32. group.addTask {
  33. try await withThrowingTaskGroup(of: Void.self) { clientGroup in
  34. let client = GRPCClient(transport: inProcess.client)
  35. clientGroup.addTask {
  36. try await client.run()
  37. }
  38. try await interopTestCase.makeTest().run(client: client)
  39. clientGroup.cancelAll()
  40. }
  41. }
  42. try await group.next()
  43. group.cancelAll()
  44. }
  45. } catch let error as AssertionFailure {
  46. XCTFail(error.message)
  47. }
  48. }
  49. func testEmptyUnary() async throws {
  50. try await self.runInProcessTransport(interopTestCase: .emptyUnary)
  51. }
  52. func testLargeUnary() async throws {
  53. try await self.runInProcessTransport(interopTestCase: .largeUnary)
  54. }
  55. func testClientStreaming() async throws {
  56. try await self.runInProcessTransport(interopTestCase: .clientStreaming)
  57. }
  58. func testServerStreaming() async throws {
  59. try await self.runInProcessTransport(interopTestCase: .serverStreaming)
  60. }
  61. func testPingPong() async throws {
  62. try await self.runInProcessTransport(interopTestCase: .pingPong)
  63. }
  64. func testEmptyStream() async throws {
  65. try await self.runInProcessTransport(interopTestCase: .emptyStream)
  66. }
  67. func testCustomMetdata() async throws {
  68. try await self.runInProcessTransport(interopTestCase: .customMetadata)
  69. }
  70. func testStatusCodeAndMessage() async throws {
  71. try await self.runInProcessTransport(interopTestCase: .statusCodeAndMessage)
  72. }
  73. func testSpecialStatusMessage() async throws {
  74. try await self.runInProcessTransport(interopTestCase: .specialStatusMessage)
  75. }
  76. func testUnimplementedMethod() async throws {
  77. try await self.runInProcessTransport(interopTestCase: .unimplementedMethod)
  78. }
  79. func testUnimplementedService() async throws {
  80. try await self.runInProcessTransport(interopTestCase: .unimplementedService)
  81. }
  82. }