Skip to content

Commit

Permalink
Use raw HTTP handlers in test-in-flight-request-cancellation
Browse files Browse the repository at this point in the history
This works just as good as the raw TCP server but hopefully doesn't make future readers have to do a
double-take.
  • Loading branch information
DerGuteMoritz committed Mar 12, 2024
1 parent 6289649 commit 810aad7
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions test/aleph/http_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1074,13 +1074,10 @@
(Thread/sleep 5)
(s/put! s (encode-http-object response))))

(defmacro with-tcp-server [handler & body]
`(with-server (tcp/start-server ~handler {:port port
:shutdown-timeout 0})
~@body))

(defmacro with-tcp-response [response & body]
`(with-tcp-server (tcp-handler ~response) ~@body))
`(with-server (tcp/start-server (tcp-handler ~response) {:port port
:shutdown-timeout 0})
~@body))

(defmacro with-tcp-request-handler [handler options request & body]
`(with-server (http/start-server ~handler (merge http-server-options ~options))
Expand Down Expand Up @@ -1446,12 +1443,11 @@
(deftest test-in-flight-request-cancellation
(let [conn-established (promise)
conn-closed (promise)]
(with-tcp-server (fn [s _]
(deliver conn-established true)
;; Required for the client close to be detected
(s/consume identity s)
(s/on-closed s (fn []
(deliver conn-closed true))))
(with-raw-handler (fn [req]
(deliver conn-established true)
(s/on-closed (:body req)
(fn []
(deliver conn-closed true))))
(let [rsp (http-get "/")]
(is (= true (deref conn-established 1000 :timeout)))
(http/cancel-request! rsp)
Expand Down

0 comments on commit 810aad7

Please sign in to comment.