|
| 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 | + |
| 17 | +import GRPCCore |
| 18 | +import GRPCInProcessTransport |
| 19 | +import XCTest |
| 20 | + |
| 21 | +@testable import InteroperabilityTests |
| 22 | + |
| 23 | +@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) |
| 24 | +final class InProcessInteroperabilityTests: XCTestCase { |
| 25 | + func runInProcessTransport( |
| 26 | + interopTestCase: InteroperabilityTestCase |
| 27 | + ) async throws { |
| 28 | + do { |
| 29 | + let inProcess = InProcessTransport.makePair() |
| 30 | + try await withThrowingTaskGroup(of: Void.self) { group in |
| 31 | + group.addTask { |
| 32 | + let server = GRPCServer(transports: [inProcess.server], services: [TestService()]) |
| 33 | + try await server.run() |
| 34 | + } |
| 35 | + |
| 36 | + group.addTask { |
| 37 | + try await withThrowingTaskGroup(of: Void.self) { clientGroup in |
| 38 | + let client = GRPCClient(transport: inProcess.client) |
| 39 | + clientGroup.addTask { |
| 40 | + try await client.run() |
| 41 | + } |
| 42 | + try await interopTestCase.makeTest().run(client: client) |
| 43 | + |
| 44 | + clientGroup.cancelAll() |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + try await group.next() |
| 49 | + group.cancelAll() |
| 50 | + } |
| 51 | + } catch let error as AssertionFailure { |
| 52 | + XCTFail(error.message) |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + func testEmtyUnary() async throws { |
| 57 | + try await self.runInProcessTransport(interopTestCase: .emptyUnary) |
| 58 | + } |
| 59 | + |
| 60 | + func testLargeUnary() async throws { |
| 61 | + try await self.runInProcessTransport(interopTestCase: .largeUnary) |
| 62 | + } |
| 63 | + |
| 64 | + func testClientStreaming() async throws { |
| 65 | + try await self.runInProcessTransport(interopTestCase: .clientStreaming) |
| 66 | + } |
| 67 | + |
| 68 | + func testServerStreaming() async throws { |
| 69 | + try await self.runInProcessTransport(interopTestCase: .serverStreaming) |
| 70 | + } |
| 71 | + |
| 72 | + func testPingPong() async throws { |
| 73 | + try await self.runInProcessTransport(interopTestCase: .pingPong) |
| 74 | + } |
| 75 | + |
| 76 | + func testEmptyStream() async throws { |
| 77 | + try await self.runInProcessTransport(interopTestCase: .emptyStream) |
| 78 | + } |
| 79 | + |
| 80 | + func testCustomMetdata() async throws { |
| 81 | + try await self.runInProcessTransport(interopTestCase: .customMetadata) |
| 82 | + } |
| 83 | + |
| 84 | + func testStatusCodeAndMessage() async throws { |
| 85 | + try await self.runInProcessTransport(interopTestCase: .statusCodeAndMessage) |
| 86 | + } |
| 87 | + |
| 88 | + func testSpecialStatusMessage() async throws { |
| 89 | + try await self.runInProcessTransport(interopTestCase: .specialStatusMessage) |
| 90 | + } |
| 91 | + |
| 92 | + func testUnimplementedMethod() async throws { |
| 93 | + try await self.runInProcessTransport(interopTestCase: .unimplementedMethod) |
| 94 | + } |
| 95 | + |
| 96 | + func testUnimplementedService() async throws { |
| 97 | + try await self.runInProcessTransport(interopTestCase: .unimplementedService) |
| 98 | + } |
| 99 | +} |
0 commit comments