Skip to content
Snippets Groups Projects
  1. Jun 29, 2023
    • Will McCutchen's avatar
      Improve /drip semantics (#132) · a6709422
      Will McCutchen authored
      This started with me wading into the `/drip` endpoint to add
      `Server-Timing` trailers as suggested in
      https://github.com/mccutchen/go-httpbin/issues/72.
      
      In making those changes, I discovered that the standard golang net/http
      server we're building on only supports sending trailers when the
      response is written using `Content-Encoding: chunked`. Initially, I
      thought it would be reasonable for this endpoint, which is designed to
      stream writes to the client, to switch over to a chunked response, but
      upon further consideration I don't think that's a good idea. So I'll
      defer adding trailers to some later work.
      
      But, in thinking this through (and fighting with the unit tests already
      in place for drip), I realized that the `/drip` endpoint had room for
      improvement, if we think about it as an endpoint _designed to let
      clients test their behavior when an HTTP server is responding very
      slowly_.
      
      So, we ended up with these changes:
      
      Initial delay semantics:
      - Originally, `/drip` would immediately write the desired status code
      and then wait for the initial delay (if any).
      - Here we update that so that it waits for the initial delay before
      writing anything to the response, to better simulate a server that is
      just very slow to respond at all.
      
      Incremental write timings:
      - Switch over to a ticker to more accurately pace the incremental writes
      across the requested duration
      - Stop sleeping after the final byte is written (should not affect
      clients, but avoids wasting server resources)
      
      Worth noting that I now believe it's important that this endpoint
      **not** switch over to chunked content encoding, because it is useful to
      maintain and endpoint that simulates a server very slowly writing a
      "normal" HTTP response.
      Unverified
      a6709422
  2. Jun 28, 2023
    • Will McCutchen's avatar
      Refactor test suite to make real requests to a real server (#131) · 0de8ec96
      Will McCutchen authored
      In the course of validating #125, we discovered that using the stdlib's
      [`httptest.ResponseRecorder`][0] mechanism to drive the vast majority of
      our unit tests led to some slight brokenness due to subtle differences
      in the way those "simulated" requests are handled vs "real" requests to
      a live HTTP server, as [explained in this comment][1].
      
      That prompted me to do a big ass refactor of the entire test suite,
      swapping httptest.ResponseRecorder for interacting with a live server
      instance via [`httptest.Server`][2].
      
      This should make the test suite more accurate and reliable in the long
      run by ensuring that the vast majority of tests are making actual HTTP
      requests and reading responses from the wire.
      
      Note that updating these tests also uncovered a few minor bugs in
      existing handler code, fixed in a separate commit for visibility.
      
      P.S. I'm awfully sorry to anyone who tries to merge or rebase local test
      changes after this refactor lands, that is goign to be a nightmare. If
      you run into issues resolving conflicts, feel free to ping me and I can
      try to help!
      
      [0]: https://pkg.go.dev/net/http/httptest#ResponseRecorder
      [1]: https://github.com/mccutchen/go-httpbin/pull/125#issuecomment-1596176645
      [2]: https://pkg.go.dev/net/http/httptest#Server
      Unverified
      0de8ec96
Loading