grpc-swift
grpc-swift copied to clipboard
Using requestHandler from tests
I can't get the requestHandlers to fire from within tests using FakeChannel
I wrote a failing test, is something like this expected to work?
https://github.com/davisg123/grpc-swift/commit/6927f25e9f265e2318f070a780063b4ab2160989
In what way does the test you wrote fail?
The requestHandler is never invoked so the requestSeen expectation times out
But concretely everything else passes? And the prior version of the test passed too?
Yes the other tests all pass and before this patch the testGetWithTestClient was passing. If you apply this patch I'm confident you'll see the same issue
cc @glbrntt
It looks like the response stream is a bit too dumb here. It never waits for the appropriate requests to come through before sending response parts if it has them. For unary RPCs it already knows what it's going to respond with, so sends the response as soon as the call is made. An intermediary object which tracks the RPC state sees that the RPC has already completed and fails the writes (and drops them on the floor) before they reach the handler.
Wondering if there are any plans to address this or if there are any workarounds anyone has found?
I'm afraid not. This will end up being deprecated when async/await support is added as it is does not fit with the model of Sendable which gRPC will use. Although it's not a direct alternative the suggestion is to use a localhost client/server instead.