Skip to content

Commit 07123ed

Browse files
authored
Adopt swift-testing for MethodConfig tests (#2055)
Motivation: swift-testing has a number of advantages over XCTest (parameterisation, organisation, failure messages etc.), we should start using it instead of XCTest. Modifications: - Convert the MethodConfig coding tests - Fixed a couple of bugs found by additional testing Results: Fewer bugs, better tests
1 parent 971b53e commit 07123ed

18 files changed

+461
-359
lines changed

Package@swift-6.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ extension Target {
415415
.protobuf,
416416
.testing,
417417
],
418+
resources: [
419+
.copy("Configuration/Inputs")
420+
],
418421
swiftSettings: [.swiftLanguageMode(.v6), .enableUpcomingFeature("ExistentialAny")]
419422
)
420423
}

Sources/GRPCCore/Configuration/MethodConfig.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ extension MethodConfig: Codable {
453453
public func encode(to encoder: any Encoder) throws {
454454
var container = encoder.container(keyedBy: CodingKeys.self)
455455
try container.encode(self.names, forKey: .name)
456+
try container.encodeIfPresent(self.waitForReady, forKey: .waitForReady)
456457
try container.encodeIfPresent(
457458
self.timeout.map { GoogleProtobufDuration(duration: $0) },
458459
forKey: .timeout
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"maxAttempts": 1,
3+
"hedgingDelay": "1s",
4+
"nonFatalStatusCodes": ["ABORTED"]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"maxAttempts": 3,
3+
"hedgingDelay": "1s",
4+
"nonFatalStatusCodes": ["ABORTED"]
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": [
3+
{
4+
"service": "echo.Echo",
5+
"method": "Get"
6+
}
7+
],
8+
"waitForReady": true,
9+
"timeout": "1s",
10+
"maxRequestMessageBytes": 1024,
11+
"maxResponseMessageBytes": 2048
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"service": "foo.bar",
3+
"method": "baz"
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"service": "foo.bar"
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"maxAttempts": 3,
3+
"initialBackoff": "1s",
4+
"maxBackoff": "3s",
5+
"backoffMultiplier": -1.6,
6+
"retryableStatusCodes": ["ABORTED", "UNAVAILABLE"]
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"maxAttempts": 3,
3+
"initialBackoff": "0s",
4+
"maxBackoff": "3s",
5+
"backoffMultiplier": 1.6,
6+
"retryableStatusCodes": ["ABORTED", "UNAVAILABLE"]
7+
}

0 commit comments

Comments
 (0)