Skip to content

Commit

Permalink
Adopt swift-testing for MethodConfig tests (#2055)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
glbrntt committed Sep 18, 2024
1 parent 971b53e commit 07123ed
Show file tree
Hide file tree
Showing 18 changed files with 461 additions and 359 deletions.
3 changes: 3 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ extension Target {
.protobuf,
.testing,
],
resources: [
.copy("Configuration/Inputs")
],
swiftSettings: [.swiftLanguageMode(.v6), .enableUpcomingFeature("ExistentialAny")]
)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/GRPCCore/Configuration/MethodConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ extension MethodConfig: Codable {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.names, forKey: .name)
try container.encodeIfPresent(self.waitForReady, forKey: .waitForReady)
try container.encodeIfPresent(
self.timeout.map { GoogleProtobufDuration(duration: $0) },
forKey: .timeout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"maxAttempts": 1,
"hedgingDelay": "1s",
"nonFatalStatusCodes": ["ABORTED"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"maxAttempts": 3,
"hedgingDelay": "1s",
"nonFatalStatusCodes": ["ABORTED"]
}
12 changes: 12 additions & 0 deletions Tests/GRPCCoreTests/Configuration/Inputs/method_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": [
{
"service": "echo.Echo",
"method": "Get"
}
],
"waitForReady": true,
"timeout": "1s",
"maxRequestMessageBytes": 1024,
"maxResponseMessageBytes": 2048
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"service": "foo.bar",
"method": "baz"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"service": "foo.bar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"maxAttempts": 3,
"initialBackoff": "1s",
"maxBackoff": "3s",
"backoffMultiplier": -1.6,
"retryableStatusCodes": ["ABORTED", "UNAVAILABLE"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"maxAttempts": 3,
"initialBackoff": "0s",
"maxBackoff": "3s",
"backoffMultiplier": 1.6,
"retryableStatusCodes": ["ABORTED", "UNAVAILABLE"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"maxAttempts": 1,
"initialBackoff": "1s",
"maxBackoff": "3s",
"backoffMultiplier": 1.6,
"retryableStatusCodes": ["ABORTED", "UNAVAILABLE"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"maxAttempts": 3,
"initialBackoff": "1s",
"maxBackoff": "0s",
"backoffMultiplier": 1.6,
"retryableStatusCodes": ["ABORTED", "UNAVAILABLE"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"maxAttempts": 3,
"initialBackoff": "1s",
"maxBackoff": "3s",
"backoffMultiplier": 1.6,
"retryableStatusCodes": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"maxAttempts": 3,
"initialBackoff": "1s",
"maxBackoff": "3s",
"backoffMultiplier": 1.6,
"retryableStatusCodes": ["ABORTED", "UNAVAILABLE"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": [
{
"service": "echo.Echo",
"method": "Get"
}
],
"waitForReady": true,
"timeout": "1s",
"maxRequestMessageBytes": 1024,
"maxResponseMessageBytes": 2048,
"hedgingPolicy": {
"maxAttempts": 3,
"hedgingDelay": "42s",
"nonFatalStatusCodes": [
"ABORTED",
"UNIMPLEMENTED"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": [
{
"service": "echo.Echo",
"method": "Get"
}
],
"waitForReady": true,
"timeout": "1s",
"maxRequestMessageBytes": 1024,
"maxResponseMessageBytes": 2048,
"retryPolicy": {
"maxAttempts": 3,
"initialBackoff": "1s",
"maxBackoff": "3s",
"backoffMultiplier": 1.6,
"retryableStatusCodes": [
"ABORTED",
"UNIMPLEMENTED"
]
}
}
Loading

0 comments on commit 07123ed

Please sign in to comment.