|
3 | 3 | [ring.adapter.jetty :refer [run-jetty]]
|
4 | 4 | [clj-http.client :as http]
|
5 | 5 | [clojure.java.io :as io]
|
| 6 | + [clojure.string :as str] |
6 | 7 | [hato.websocket :as hato]
|
7 | 8 | [less.awful.ssl :as less-ssl]
|
8 | 9 | [ring.core.protocols :as p]
|
|
474 | 475 | {:status 200
|
475 | 476 | :headers {"Transfer-Encoding" "chunked"}
|
476 | 477 | :body (SequenceInputStream.
|
477 |
| - (ByteArrayInputStream. (.getBytes (str (range 100000)) "UTF-8")) |
| 478 | + (ByteArrayInputStream. |
| 479 | + (.getBytes (apply str (range 100000)) "UTF-8")) |
478 | 480 | (proxy [InputStream] []
|
479 | 481 | (read
|
480 | 482 | ([] (throw (IOException. "test error")))
|
|
493 | 495 | (response (chunked-lazy-seq-with-error request))))
|
494 | 496 |
|
495 | 497 | (deftest streaming-with-error
|
496 |
| - (testing "chunked stream without sending termination chunk on error" |
| 498 | + (testing "chunked stream interrupted by error" |
497 | 499 | (with-server chunked-stream-with-error {:port test-port}
|
498 |
| - (is (thrown? MalformedChunkCodingException (http/get test-url))))) |
| 500 | + (let [response (http/get test-url)] |
| 501 | + (is (= 200 (:status response))) |
| 502 | + (is (str/ends-with? (:body response) "99999"))))) |
499 | 503 |
|
500 |
| - (testing "chunked sequence without sending termination chunk on error" |
| 504 | + (testing "chunked sequence interrupted by error" |
501 | 505 | (with-server chunked-lazy-seq-with-error {:port test-port}
|
502 |
| - (is (thrown? MalformedChunkCodingException (http/get test-url))))) |
| 506 | + (let [response (http/get test-url)] |
| 507 | + (is (= 200 (:status response))) |
| 508 | + (is (str/ends-with? (:body response) "99999"))))) |
503 | 509 |
|
504 |
| - (testing "async chunked stream without sending termination chunk on error" |
| 510 | + (testing "async chunked stream interrupted by error" |
505 | 511 | (with-server chunked-stream-with-error {:port test-port :async? true}
|
506 |
| - (is (thrown? MalformedChunkCodingException (http/get test-url))))) |
| 512 | + (let [response (http/get test-url)] |
| 513 | + (is (= 200 (:status response))) |
| 514 | + (is (str/ends-with? (:body response) "99999"))))) |
507 | 515 |
|
508 |
| - (testing "async chunked sequence without sending termination chunk on error" |
| 516 | + (testing "async chunked sequence interrupted by error" |
509 | 517 | (with-server chunked-lazy-seq-with-error {:port test-port :async? true}
|
510 |
| - (is (thrown? MalformedChunkCodingException (http/get test-url)))))) |
| 518 | + (let [response (http/get test-url)] |
| 519 | + (is (= 200 (:status response))) |
| 520 | + (is (str/ends-with? (:body response) "99999")))))) |
511 | 521 |
|
512 | 522 | (def thread-exceptions (atom []))
|
513 | 523 |
|
|
985 | 995 | [:t "t: one"]
|
986 | 996 | [:t "b: two"]]
|
987 | 997 | @log)))))
|
| 998 | + |
| 999 | +(defn make-client-timeout-handler [ex-callback] |
| 1000 | + (fn [_ respond raise] |
| 1001 | + (let [response {:status 200 |
| 1002 | + :body (reify p/StreamableResponseBody |
| 1003 | + (write-body-to-stream [_ _ os] |
| 1004 | + (with-open [os os] |
| 1005 | + (.write os (.getBytes "foo")) |
| 1006 | + (.flush os) |
| 1007 | + (Thread/sleep 100) |
| 1008 | + (.write os (.getBytes " bar")) |
| 1009 | + (.flush os))))}] |
| 1010 | + (try (respond response) |
| 1011 | + (catch Exception ex (ex-callback ex))) |
| 1012 | + (try (raise (ex-info "Test" {})) |
| 1013 | + (catch Exception ex (ex-callback ex))) |
| 1014 | + (ex-callback nil)))) |
| 1015 | + |
| 1016 | +(deftest test-callbacks-do-not-throw |
| 1017 | + (let [raised (promise) |
| 1018 | + handler (make-client-timeout-handler raised)] |
| 1019 | + (with-server handler {:port test-port, :async? true} |
| 1020 | + (try (http/get (str test-url "/") {:socket-timeout 50}) |
| 1021 | + (catch java.net.SocketTimeoutException _)) |
| 1022 | + (is (nil? (deref raised 200 :error)))))) |
0 commit comments