Rocket icon indicating copy to clipboard operation
Rocket copied to clipboard

Route tracing

Open the10thWiz opened this issue 2 years ago • 4 comments

Adds support for testing which route generated a response. This is an implementation of the ideas I put forward in #1878, with a few minor changes. First, I did not create a macro, since my implementation works just fine with a generic type parameter. Writing a macro is pretty trivial, if it's desired. I also added tests to the hello world example to demonstrate what the actual tests look like.

There are a few improvements that could be made:

  • [x] The methods added to LocalResponse (routed_by, caught_by and was_caught) could probably have better names.
  • [x] The Request object could (in testing mode) track which routes were attempted, and some basic information about the result. This should be pretty trivial to add, although it may require more that just the route's TypeId to actually use this to produce meaningful information.

The only regression I see is that Catcher now has a private member, so other crates cannot directly construct a Catcher, but I think this is acceptable, since it should probably be constructed with the constructor as before.

the10thWiz avatar May 09 '22 17:05 the10thWiz

It looks like the issue with Windows Debug is a memory or hard drive error.

the10thWiz avatar May 11 '22 18:05 the10thWiz

Indeed, we're running out of disk space. Let's disregard it for now.

SergioBenitez avatar May 11 '22 19:05 SergioBenitez

I think I've reached an API I'm pretty happy with. Since the type tracking is done internally, this could be extended to support listing the routes attempted in order, but I don't think that's necessary for this PR. I'm also happy enough with the syntax presented here, I don't feel the need to introduce a new assert macro. @SergioBenitez, this PR is ready for a review, whenever you get a chance.

the10thWiz avatar Sep 14 '23 16:09 the10thWiz

I've rebased on the latest master and push to your fork so that I can review.

SergioBenitez avatar Oct 18 '23 08:10 SergioBenitez