Skip to content

Commit 108a0b9

Browse files
Unit tests for interop tests (#1823)
Motivation: We need unit tests that run the interop tests with the in process transport. Modifications: Created a test target and implemented the tests for each interop test, that catch AssertionFailure errors when the interop tests fail. Result: We will run the interop tests with the in process transport.
1 parent a060296 commit 108a0b9

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

Package.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,15 @@ extension Target {
361361
]
362362
)
363363

364+
static let inProcessInteroperabilityTests: Target = .testTarget(
365+
name: "InProcessInteroperabilityTests",
366+
dependencies: [
367+
.grpcInProcessTransport,
368+
.interoperabilityTests,
369+
.grpcCore
370+
]
371+
)
372+
364373
static let interopTestModels: Target = .target(
365374
name: "GRPCInteroperabilityTestModels",
366375
dependencies: [
@@ -724,6 +733,7 @@ let package = Package(
724733
.grpcHTTP2TransportNIOTransportServicesTests,
725734
.grpcProtobufTests,
726735
.grpcProtobufCodeGenTests,
736+
.inProcessInteroperabilityTests
727737
]
728738
)
729739

Sources/InteroperabilityTests/InteroperabilityTestCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public enum InteroperabilityTestCase: String, CaseIterable {
6666
}
6767
}
6868

69-
@available(macOS 13.0, *)
69+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
7070
extension InteroperabilityTestCase {
7171
/// Return a new instance of the test case.
7272
public func makeTest() -> InteroperabilityTest {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)