Skip to content

Conversation

@stefanadranca
Copy link
Collaborator

Motivation:

We want to be able to test that the server receives metadata and can send both initial and trailing metadata.

Modifications:

  • added extensions for server requests that extract the initial and trailing metadata that should be echoed
  • added the initial and trailing metadata n the server responses

Result:

The interop tests will test that the server sends metadata as initial and trailing.

Motivation:

We want to be able to test that the server receives metadata and can send both initial and trailing metadata.

Modifications:

- added extensions for server requests that extract the initial and trailing metadata that should be echoed
- added the initial and trailing metadata n the server responses

Result:

The interop tests will test that the server sends metadata as initial and trailing.
@stefanadranca stefanadranca requested review from gjcairo and glbrntt March 8, 2024 14:09
Comment on lines 212 to 243
fileprivate func extractInitialAndTrailingMetadata() -> (Metadata, Metadata) {
var initialMetadata = Metadata()
var trailingMetadata = Metadata()

for value in self.metadata[stringValues: "x-grpc-test-echo-initial"] {
initialMetadata.addString(value, forKey: "x-grpc-test-echo-initial")
}

for value in self.metadata[binaryValues: "x-grpc-test-echo-trailing-bin"] {
trailingMetadata.addBinary(value, forKey: "x-grpc-test-echo-trailing-bin")
}

return (initialMetadata, trailingMetadata)
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension ServerRequest.Stream {
fileprivate func extractInitialAndTrailingMetadata() -> (Metadata, Metadata) {
var initialMetadata = Metadata()
var trailingMetadata = Metadata()

for value in self.metadata[stringValues: "x-grpc-test-echo-initial"] {
initialMetadata.addString(value, forKey: "x-grpc-test-echo-initial")
}

for value in self.metadata[binaryValues: "x-grpc-test-echo-trailing-bin"] {
trailingMetadata.addBinary(value, forKey: "x-grpc-test-echo-trailing-bin")
}

return (initialMetadata, trailingMetadata)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of needless repetition here. Instead can we have a fileprivate extension on Metadata which makes the initial and trailing metadata?

Then in the test functions we can just call request.metadata.makeInitialAndTrailingMetadata()?

@glbrntt glbrntt added the version/v2 Relates to v2 label Mar 11, 2024
@stefanadranca stefanadranca requested a review from glbrntt March 11, 2024 10:50
@glbrntt glbrntt enabled auto-merge (squash) March 11, 2024 13:29
@glbrntt glbrntt merged commit a060296 into grpc:main Mar 11, 2024
@gjcairo gjcairo added semver/none No version bump required. and removed semver/none No version bump required. labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version/v2 Relates to v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants