Possible escaping closure related Unimplemented
that likely can't be fixed via withEscapedDependencies
/yield
#300
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a follow up to this discussion/solution but I thought it'd start a new one because that discussion started out about
Codable
but ended up being about escaping closures.This is going to rather lenghty, apologies! I was still problem solving while writing it up and then I thought it's probably best to just leave in all the details rather than try and edit it down.
I've hit another case where I'm losing dependencies in a test and I'm not sure this is related to escaping closures, or at least not in a way where I could inject
withEscapedDependencies
/yield
.I have a Vapor test that correctly sets the dependency if I run a request it as follows:
However, it fails with an
failed - Unimplemented: 'EnvironmentClient.builderToken'
if I run it as follows:The difference is that in the
.inMemory
configuration, the test essentially short-circuits the response handling without spinning up a server. In the.running
case it starts a web server viaapp.server.start(address: .hostname(self.hostname, port: self.port))
and sends an actual HTTP request.(We need to run the latter in this test, because the short-circuit bypasses an essential part we're trying to regression test for, which funnily enough is a regression test for a Pointfree.co project 🙂)
Best I can tell, the problem comes down to the
performTest
method of the two conformersLive
/InMemory
:Live
(failing):InMemory
(succeeding):Now the dependency isn't within
app
itself but attached to a route on app. It's for the bearer token auth mechanism viaUser
:which is attached as follows:
Now it's true that there is an escaping closure involved here (*), the
use:
inprotected.on(...)
. However, passing the dependency through viawithEscpapedDependencies
andyield
doesn't help. Also note, that no weaving through of dependencies is required and the dependency is definitely being updated when the test is called via theinMemory
request test.(*) The trailing closures on
group
aren't escaping but even so I tried weaving the dependencies through as above but to no effect.I suspect the issue stems from starting a new server. Even though the
app
object should be properly instrumented with the updated dependency, inside that machinery it gets lost. In particular, I see the following inside Vapor'sHTTPServerConnection
:That's our
app
object being passed in here and this is the signature of NIO'sChannel.configureHTTP2SecureUpgrade
:Could that be the problem? If so, since I don't control any of the surrounding code, is there any way for me to make sure the dependency gets injected?
We're deep inside Vapor/NIO code here and I have no way to bring in a
withEscapedDependencies
/yield
pair...Beta Was this translation helpful? Give feedback.
All reactions