Skip to content

Commit

Permalink
server_connection: fix regression which caused wakeup_writer bookke…
Browse files Browse the repository at this point in the history
…eping to be wrong for async responses (inhabitedtype#37)

Introduced in inhabitedtype#161
  • Loading branch information
anmonteiro committed May 11, 2020
1 parent 464723c commit 84abd81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ Unreleased
[inhabitedtype/httpaf#162](https://github.com/inhabitedtype/httpaf/issues/162)
- httpaf-async: Add HTTPS support for the Async bindings
([#35](https://github.com/anmonteiro/httpaf/pull/35)).
- httpaf: Fix upstream regression introduced in
[inhabitedtype/httpaf#161](https://github.com/inhabitedtype/httpaf/pull/161)
that caused `wake_up_writer` callback bookkeeping to be slightly wrong due to
physical equality, producing runtime errors in cases where it shouldn't
([#37](https://github.com/anmonteiro/httpaf/pull/37)).

httpaf (upstream) 0.6.5
--------------
Expand Down
23 changes: 23 additions & 0 deletions lib_test/test_server_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,28 @@ let test_empty_body_no_immediate_flush () =
true !reader_woken_up;
;;

let test_yield_before_starting_a_response () =
let reader_woken_up = ref false in
let response = Response.create `OK in
let continue_response = ref (fun () -> ()) in
let request_handler reqd =
continue_response := (fun () ->
let resp_body = Reqd.respond_with_streaming reqd response in
Body.close_writer resp_body)
in
let t = create ~error_handler request_handler in
reader_ready t;
writer_yielded t;
read_request t (Request.create `GET "/");
yield_reader t (fun () -> reader_woken_up := true);
yield_writer t ignore;
!continue_response ();
write_response t ~body:"" response;
writer_yielded t;
Alcotest.(check bool) "Reader woken up"
true !reader_woken_up;
;;

let tests =
[ "initial reader state" , `Quick, test_initial_reader_state
; "shutdown reader closed", `Quick, test_reader_is_closed_after_eof
Expand Down Expand Up @@ -750,4 +772,5 @@ let tests =
; "malformed request, streaming response", `Quick, test_malformed_request_streaming_error_response
; "`flush_headers_immediately` with empty body", `Quick, test_immediate_flush_empty_body
; "empty body with no immediate flush", `Quick, test_empty_body_no_immediate_flush
; "yield before starting a response", `Quick, test_yield_before_starting_a_response
]

0 comments on commit 84abd81

Please sign in to comment.