gotham-rs / gotham

A flexible web framework that promotes stability, safety, security and speed.

Home Page:https://gotham.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TestRequest should have perform async method

technic opened this issue · comments

Hi,
I have a situation when there are two clients. One pushes some updates to the server, and the other one polls.
I want to be able to test this concurrent scenario. Currently, all test requests are done with perform() method which is blocking.
However, the internals of the TestRequest use futures, but I don't see any way to access them from public api.

Do you think we can have something like perform_async() method, that will return a future? Afterward all futures can be awaited before exiting test method.

I do think perform_async would be required for, at the very least, consistency with the to_async feature, however I am hesitant to add too much more to the 0.5 milestone. @msrd0 what are your thoughts?

commented

I think we should add this feature at some point, perhaps in a 0.5.1 or 0.6 release (sounds like a non-breaking change to me).

I don't think perform_async is the way to go. I've played around with implementing that but it is hindered by the fact that TestServer has it's own runtime.

After a while I noticed that there is almost nothing left of the TestServer once you make it asynchronous. All it does is create the TestClient with special TestConnect, but even that wrapper probably won't be necessary anymore.

So in summary: In the asynchronous case you probably only need an AsyncTestServer that creates a hyper::client::Client<TestConnect,Body> or a small wrapper around it. The runtime of the async context you're in will then be used and TestRequest also isn't required anymore because the methods on the Client can just be awaited directly.

I've just implemented a complete AsyncTestServer that should allow tests from an async context.