Skip to content

Commit eef3c66

Browse files
committed
Use raw HTTP handlers in test-in-flight-request-cancellation
This works just as good as the raw TCP server but hopefully doesn't make future readers have to do a double-take.
1 parent 5bbe93d commit eef3c66

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

test/aleph/http_test.clj

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,13 +1074,10 @@
10741074
(Thread/sleep 5)
10751075
(s/put! s (encode-http-object response))))
10761076

1077-
(defmacro with-tcp-server [handler & body]
1078-
`(with-server (tcp/start-server ~handler {:port port
1079-
:shutdown-timeout 0})
1080-
~@body))
1081-
10821077
(defmacro with-tcp-response [response & body]
1083-
`(with-tcp-server (tcp-handler ~response) ~@body))
1078+
`(with-server (tcp/start-server (tcp-handler ~response) {:port port
1079+
:shutdown-timeout 0})
1080+
~@body))
10841081

10851082
(defmacro with-tcp-request-handler [handler options request & body]
10861083
`(with-server (http/start-server ~handler (merge http-server-options ~options))
@@ -1446,12 +1443,11 @@
14461443
(deftest test-in-flight-request-cancellation
14471444
(let [conn-established (promise)
14481445
conn-closed (promise)]
1449-
(with-tcp-server (fn [s _]
1450-
(deliver conn-established true)
1451-
;; Required for the client close to be detected
1452-
(s/consume identity s)
1453-
(s/on-closed s (fn []
1454-
(deliver conn-closed true))))
1446+
(with-raw-handler (fn [req]
1447+
(deliver conn-established true)
1448+
(s/on-closed (:body req)
1449+
(fn []
1450+
(deliver conn-closed true))))
14551451
(let [rsp (http-get "/")]
14561452
(is (= true (deref conn-established 1000 :timeout)))
14571453
(http/cancel-request! rsp)

0 commit comments

Comments
 (0)