grpc-swift icon indicating copy to clipboard operation
grpc-swift copied to clipboard

[feature] In-process Transport

Open timburks opened this issue 6 years ago • 8 comments

The gRPC C core currently supports multiple transports including an in-process transport. According to the gRPC team, this is "quite popular for hermetic testing" and is being added to other gRPC implementations. gRPC-Java currently has it and work is underway to have this in gRPC-Go in another quarter or two.

There have been requests for this in gRPC-Swift. I haven't verified this, but presumably it would be easy to enable this in the cgrpc implementation. Are we interested in adding it to the NIO version?

timburks avatar Sep 11 '19 23:09 timburks

I will definitely use this feature in the NIO version. I'm writing a library that integrates Swift gRPC with Apple's Combine framework, and I'm currently going over the network for my end-to-end tests. It would be useful to be able to keep these in-process.

vyshane avatar Sep 12 '19 13:09 vyshane

I definitely see the value in this.

I'm not sure what this would look like at the moment. We might have to implement another NIO.Channel and target (i.e. in the client/server Configuration) to connect/bind to. That would minimise the differences in setup and use from the user perspective.

glbrntt avatar Sep 13 '19 13:09 glbrntt

This sounds like using NIO's EmbeddedChannel?

MrMage avatar Nov 13 '19 11:11 MrMage

It depends on the use case: EmbeddedChannel uses EmbeddedEventLoop which doesn't have a proper eventing mechanism so you have to manually read from the channel (and you need to write some glue to go between the client and server channels) which is fine for unit tests but probably not ideal for end-to-end tests. The same goes for time: the user of the EmbeddedEventLoop has to manually advance time which also doesn't seem appropriate here.

One possibility could be using a PipeChannel (https://apple.github.io/swift-nio/docs/current/NIO/Classes/NIOPipeBootstrap.html) but we'd need to look into this some more!

glbrntt avatar Nov 13 '19 12:11 glbrntt

That makes sense, I was not aware of the difference. Thank you for the elaboration!

MrMage avatar Nov 14 '19 08:11 MrMage

@glbrntt have we fully resolved this yet by using EmbeddedChannel in tests?

MrMage avatar Mar 19 '20 13:03 MrMage

Not quite: the EmbeddedChannel client and use on the server is purely internal at this point. It's also quite manual, you have to tell two embedded channels to exchange messages in a loop. We should keep this one open.

glbrntt avatar Mar 19 '20 13:03 glbrntt