|
143 | 143 | (is (= (:status response) 200)) |
144 | 144 | (is (= (:body response) hello-body)))))) |
145 | 145 |
|
| 146 | +(defn await-result |
| 147 | + [result timeout-ms description] |
| 148 | + (let [timeout-value ::timeout |
| 149 | + value (deref result timeout-ms timeout-value)] |
| 150 | + (is (not= timeout-value value) |
| 151 | + (str "Timed out waiting for " description)) |
| 152 | + value)) |
| 153 | + |
| 154 | +(defn request-failed? |
| 155 | + [response] |
| 156 | + (or (some? (:error response)) |
| 157 | + (not= 200 (:status response)))) |
| 158 | + |
146 | 159 | (deftest basic-ring-test |
147 | 160 | (testing "ring request over http succeeds" |
148 | 161 | (validate-ring-handler |
|
723 | 736 | (with-app-with-config |
724 | 737 | app |
725 | 738 | [jetty12-service] |
726 | | - {:webserver {:port 8080 :shutdown-timeout-seconds 10}} |
| 739 | + {:webserver {:port 8080 |
| 740 | + :shutdown-timeout-seconds 10 |
| 741 | + :gzip-enable false}} |
727 | 742 | (let [s (tk-app/get-service app :WebserverService) |
728 | 743 | add-ring-handler (partial add-ring-handler s) |
729 | 744 | in-request-handler (promise) |
730 | 745 | ring-handler (fn [_] |
731 | 746 | (deliver in-request-handler true) |
732 | | - (Thread/sleep 3000) |
| 747 | + (Thread/sleep 1000) |
733 | 748 | {:status 200 :body "Hello, World!"})] |
734 | 749 | (add-ring-handler ring-handler "/hello") |
735 | | - (with-open [async-client (async/create-client {})] |
| 750 | + (with-open [async-client (async/create-client {:socket-timeout-milliseconds 30000})] |
736 | 751 | (let [response (http-client-common/get async-client "http://localhost:8080/hello" {:as :text})] |
737 | 752 | @in-request-handler |
738 | 753 | (tk-app/stop app) |
739 | | - (is (= (:status @response) 200)) |
740 | | - (is (= (:body @response) "Hello, World!"))))))) |
| 754 | + (let [response (await-result response 15000 "graceful shutdown response")] |
| 755 | + (is (nil? (:error response)) |
| 756 | + (str "Unexpected request error during graceful shutdown: " (:error response))) |
| 757 | + (is (= (:status response) 200)) |
| 758 | + (is (= (:body response) "Hello, World!")))))))) |
741 | 759 |
|
742 | 760 | (testing "jetty12's stop timeout can be changed from config" |
743 | 761 | (with-app-with-config |
744 | 762 | app |
745 | 763 | [jetty12-service] |
746 | | - {:webserver {:port 8080 :shutdown-timeout-seconds 1}} |
| 764 | + {:webserver {:port 8080 |
| 765 | + :shutdown-timeout-seconds 1 |
| 766 | + :gzip-enable false}} |
747 | 767 | (let [s (tk-app/get-service app :WebserverService) |
748 | 768 | add-ring-handler (partial add-ring-handler s) |
749 | 769 | in-request-handler (promise) |
|
752 | 772 | (Thread/sleep 2000) |
753 | 773 | {:status 200 :body "Hello, World!"})] |
754 | 774 | (add-ring-handler ring-handler "/hello") |
755 | | - (with-open [async-client (async/create-client {})] |
| 775 | + (with-open [async-client (async/create-client {:socket-timeout-milliseconds 30000})] |
756 | 776 | (let [response (http-client-common/get async-client "http://localhost:8080/hello" {:as :text})] |
757 | 777 | @in-request-handler |
758 | 778 | (tk-log-testutils/with-test-logging |
759 | 779 | (tk-app/stop app)) |
760 | | - (is (not (nil? (:error @response))))))))) |
| 780 | + (let [response (await-result response 15000 "request interrupted after shutdown timeout")] |
| 781 | + (is (request-failed? response) |
| 782 | + (str "Expected in-flight request to fail after stop timeout expired, got: " response)))))))) |
761 | 783 |
|
762 | 784 | ; Per [TK-437](https://tickets.puppetlabs.com/browse/TK-437) we've been having issues |
763 | 785 | ; with this test randomly hanging, but the fixes applied for TK-437 didn't seem to resolve |
|
837 | 859 | app |
838 | 860 | [jetty12-service |
839 | 861 | sleepy-service] |
840 | | - {:webserver {:port 8080 :shutdown-timeout-seconds 1}} |
841 | | - (with-open [async-client (async/create-client {})] |
| 862 | + {:webserver {:port 8080 |
| 863 | + :shutdown-timeout-seconds 1 |
| 864 | + :gzip-enable false}} |
| 865 | + (with-open [async-client (async/create-client {:socket-timeout-milliseconds 30000})] |
842 | 866 | (let [response (http-client-common/get async-client "http://localhost:8080/hi_world" {:as :text})] |
843 | 867 | @in-request-handler? |
844 | 868 | (tk-app/restart app) |
845 | | - (is (not (nil? (:error @response))))) |
| 869 | + (let [response (await-result response 15000 "request interrupted during restart")] |
| 870 | + (is (request-failed? response) |
| 871 | + (str "Expected in-flight request to fail during restart, got: " response)))) |
846 | 872 | (deliver unblock-request? true) |
847 | 873 | (let [response (http-client-common/get async-client "http://localhost:8080/hi_world" {:as :text})] |
848 | | - (is (= 200 (:status @response))) |
849 | | - (is (= hello-body (:body @response)))))))))) |
| 874 | + (let [response (await-result response 15000 "post-restart request")] |
| 875 | + (is (= 200 (:status response))) |
| 876 | + (is (= hello-body (:body response))))))))))) |
850 | 877 |
|
851 | 878 | (deftest double-stop-test |
852 | 879 | (testing "if the stop lifecycle is called more than once, we handle that gracefully and quietly" |
|
0 commit comments