|
9 | 9 | [flow :as flow]
|
10 | 10 | [ssl :as ssl]
|
11 | 11 | [tcp :as tcp]]
|
12 |
| - [aleph.http.core :as core] |
13 | 12 | [clj-commons.byte-streams :as bs]
|
14 | 13 | [manifold.deferred :as d]
|
15 |
| - [manifold.stream :as s]) |
| 14 | + [manifold.stream :as s] |
| 15 | + [manifold.time :as t]) |
16 | 16 | (:import
|
17 | 17 | (java.io
|
18 | 18 | File)
|
|
490 | 490 | (set-prop initial-threads-property)
|
491 | 491 | (clear-prop))))
|
492 | 492 |
|
| 493 | +(defn- slow-stream |
| 494 | + "Produces a `manifold.stream` which yield a value |
| 495 | + every 50 milliseconds six times." |
| 496 | + [] |
| 497 | + (let [body (s/stream 10)] |
| 498 | + (-> (d/loop [cnt 0] |
| 499 | + (t/in 50 |
| 500 | + (fn [] |
| 501 | + (d/chain' (s/put! body (str cnt)) |
| 502 | + (fn [_] |
| 503 | + (when (< cnt 5) |
| 504 | + (d/recur (inc cnt)))))))) |
| 505 | + (d/chain' (fn [_] (s/close! body)))) |
| 506 | + body)) |
| 507 | + |
| 508 | +(deftest test-idle-timeout |
| 509 | + (let [url (str "http://localhost:" port) |
| 510 | + echo-handler (fn [{:keys [body]}] {:body (bs/to-string body)}) |
| 511 | + slow-handler (fn [_] {:body (slow-stream)})] |
| 512 | + (testing "Server is slow to write" |
| 513 | + (with-handler-options slow-handler {:idle-timeout 200 |
| 514 | + :port port} |
| 515 | + (is (= "012345" (bs/to-string (:body @(http/get url))))))) |
| 516 | + (testing "Server is too slow to write" |
| 517 | + (with-handler-options slow-handler {:idle-timeout 30 |
| 518 | + :port port} |
| 519 | + (is (= "" |
| 520 | + (bs/to-string (:body @(http/get url))))))) |
| 521 | + (testing "Client is slow to write" |
| 522 | + (with-handler-options echo-handler {:idle-timeout 200 |
| 523 | + :port port |
| 524 | + :raw-stream? true} |
| 525 | + (is (= "012345" (bs/to-string (:body @(http/put url {:body (slow-stream)}))))))) |
| 526 | + (testing "Client is too slow to write" |
| 527 | + (with-handler-options echo-handler {:idle-timeout 30 |
| 528 | + :port port |
| 529 | + :raw-stream? true} |
| 530 | + (is (thrown-with-msg? Exception #"connection was close" |
| 531 | + (bs/to-string (:body @(http/put url {:body (slow-stream)}))))))))) |
493 | 532 | ;;;
|
494 | 533 |
|
495 | 534 | (deftest test-large-responses
|
|
0 commit comments