Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
adds parallel streaming tests for http and h2 connections to backends (
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsimam authored and DaoWen committed Jul 9, 2019
1 parent 1e14c50 commit 5a0d19b
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 88 deletions.
5 changes: 3 additions & 2 deletions containers/test-apps/nginx/data/nginx-template.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error_log nginx_error.log;
error_log nginx_error.log info;
pid nginx.pid;
worker_processes 1;
daemon off;
Expand All @@ -10,10 +10,11 @@ http {
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log nginx_access.log main;
error_log nginx_error.log info;

server {
listen ${PORT0} ${NGINX_SSL} ${NGINX_HTTP2};
listen ${PORT1} ${NGINX_SSL};
listen ${PORT1};

server_name localhost;

Expand Down
75 changes: 40 additions & 35 deletions waiter/integration/waiter/content_encoding_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@
[clojure.data.json :as json]
[clojure.test :refer :all]
[clojure.tools.logging :as log]
[qbits.jet.client.http :as http]
[waiter.util.client-tools :refer :all])
(:import (java.io EOFException InputStreamReader)
(org.apache.http ConnectionClosedException)))

(deftest ^:parallel ^:integration-fast test-support-success-chunked-gzip-response
(testing-using-waiter-url
(log/info "Test successful chunked gzip response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testgzipsuccesschunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [response-size 2000000
fail-after-size 8000000
req-headers (assoc service-headers
:x-waiter-debug true
:x-kitchen-chunked true
:x-kitchen-fail-after fail-after-size
:x-kitchen-response-size response-size
:x-kitchen-fail-after fail-after-size)
:x-waiter-debug true)
{:keys [headers] :as response} (make-request waiter-url "/gzip" :headers req-headers)]
(assert-response-status response 200)
(is (= (get headers "content-type") "text/plain") (str headers))
Expand All @@ -55,14 +54,14 @@
(deftest ^:parallel ^:integration-fast test-support-failed-chunked-gzip-response
(testing-using-waiter-url
(log/info "Test failed chunked gzip response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testgzipfailedchunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [req-headers (assoc service-headers
:x-waiter-debug true
:x-kitchen-chunked true
:x-kitchen-fail-after 50
:x-kitchen-response-size 1024
:x-kitchen-fail-after 50)
:x-waiter-debug true)
url (str HTTP-SCHEME waiter-url "/gzip")]
(is (thrown?
EOFException
Expand All @@ -75,16 +74,16 @@
(deftest ^:parallel ^:integration-fast test-support-success-gzip-response
(testing-using-waiter-url
(log/info "Test successful gzip response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testgzipsuccessunchunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [response-size 2000000
fail-after-size 8000000
req-headers (assoc service-headers
:x-waiter-debug true
:x-kitchen-chunked false
:x-kitchen-fail-after fail-after-size
:x-kitchen-response-size response-size
:x-kitchen-fail-after fail-after-size)
:x-waiter-debug true)
{:keys [headers] :as response} (make-request waiter-url "/gzip" :headers req-headers :verbose true)]
(assert-response-status response 200)
(is (= (get headers "content-type") "text/plain") (str headers))
Expand All @@ -103,14 +102,14 @@
(deftest ^:parallel ^:integration-fast test-support-failed-gzip-response
(testing-using-waiter-url
(log/info "Test failed gzip response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testgzipfailedunchunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [req-headers (assoc service-headers
:x-waiter-debug true
:x-kitchen-chunked false
:x-kitchen-fail-after 50
:x-kitchen-response-size 1024
:x-kitchen-fail-after 50)]
:x-waiter-debug true)]
(is (thrown?
ConnectionClosedException
(clj-http/get (str HTTP-SCHEME waiter-url "/gzip") {:headers req-headers
Expand All @@ -122,12 +121,13 @@
(deftest ^:parallel ^:integration-fast test-support-success-chunked-response
(testing-using-waiter-url
(log/info "Test successful chunked plain response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testsuccesschunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [req-headers (assoc service-headers
:x-kitchen-fail-after 200000
:x-kitchen-response-size 100000
:x-kitchen-fail-after 200000)
:x-waiter-debug true)
{:keys [body headers] :as response} (make-request waiter-url "/chunked" :headers req-headers :verbose true)
body-length (count (bytes (byte-array (map (comp byte int) (str body)))))]
(assert-response-status response 200)
Expand All @@ -142,12 +142,13 @@
(deftest ^:parallel ^:integration-fast test-support-failed-chunked-response
(testing-using-waiter-url
(log/info "Test truncated chunked plain response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testfailedchunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [req-headers (assoc service-headers
:x-kitchen-fail-after 5000
:x-kitchen-response-size 100000
:x-kitchen-fail-after 5000)
:x-waiter-debug true)
{:keys [body headers] :as response} (make-request waiter-url "/chunked" :headers req-headers :verbose true)
body-length (count (bytes (byte-array (map (comp byte int) (str body)))))]
(assert-response-status response 200)
Expand All @@ -162,32 +163,35 @@
(deftest ^:parallel ^:integration-fast test-support-success-unchunked-response
(testing-using-waiter-url
(log/info "Test successful plain response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testsuccessunchunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [req-headers (assoc service-headers
:x-kitchen-response-size 100000
:x-kitchen-fail-after 200000)
{:keys [body headers] :as response} (make-request waiter-url "/unchunked" :headers req-headers :verbose true)
body-length (count (bytes (byte-array (map (comp byte int) (str body)))))]
(assert-response-status response 200)
(is (== 100000 body-length))
(is (= (get headers "content-type") "text/plain") (str headers))
(is (nil? (get headers "content-encoding")) (str headers))
;; TODO flaky: this is sometimes missing (is (not (nil? (get headers "content-length"))) (str headers))
(is (not (nil? (get headers "x-cid"))) (str headers)))
(dotimes [_ 100]
(let [req-headers (assoc service-headers
:x-kitchen-fail-after 200000
:x-kitchen-response-size 100000
:x-waiter-debug true)
{:keys [body headers] :as response} (make-request waiter-url "/unchunked" :headers req-headers :verbose true)
body-length (count (bytes (byte-array (map (comp byte int) (str body)))))]
(assert-response-status response 200)
(is (== 100000 body-length))
(is (= (get headers "content-type") "text/plain") (str headers))
(is (nil? (get headers "content-encoding")) (str headers))
;; TODO flaky: this is sometimes missing (is (not (nil? (get headers "content-length"))) (str headers))
(is (not (nil? (get headers "x-cid"))) (str headers))))
(finally
(delete-service waiter-url service-id))))))

(deftest ^:parallel ^:integration-fast test-support-failed-unchunked-response
(testing-using-waiter-url
(log/info "Test truncated failed plain response")
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name "testfailedunchunked"))
(let [service-headers (assoc (kitchen-request-headers) :x-waiter-name (rand-name))
{:keys [service-id]} (make-request-with-debug-info service-headers #(make-kitchen-request waiter-url %))]
(try
(let [req-headers (assoc service-headers
:x-kitchen-fail-after 5000
:x-kitchen-response-size 100000
:x-kitchen-fail-after 5000)]
:x-waiter-debug true)]
(is (thrown? ConnectionClosedException
(clj-http/get (str HTTP-SCHEME waiter-url "/unchunked") {:headers req-headers
:spnego-auth use-spnego}))))
Expand All @@ -199,12 +203,13 @@
(let [data-length 1200000
chunk-size 1000
chunk-delay 100 ; wait 100 ms between each chunk, entire stream takes ~2 minutes
headers (merge (kitchen-request-headers) {:x-waiter-name (rand-name "testterminatechunkedrequest")
headers (merge (kitchen-request-headers) {:x-kitchen-chunk-delay chunk-delay
:x-kitchen-chunk-size chunk-size
:x-kitchen-response-size data-length
; ensure that each router has at least two slots available
:x-waiter-concurrency-level 20
:x-kitchen-chunk-delay chunk-delay
:x-kitchen-chunk-size chunk-size
:x-kitchen-response-size data-length})
:x-waiter-debug true
:x-waiter-name (rand-name)})
get-state (fn []
(let [{:keys [body]} (make-request waiter-url "/kitchen-state" :headers headers)]
(log/info "Body returned from /kitchen-state:" body)
Expand Down
Loading

0 comments on commit 5a0d19b

Please sign in to comment.