From 177b004144119c9245c41e1a39019e2995e11f58 Mon Sep 17 00:00:00 2001 From: craff Date: Sat, 14 Jan 2023 17:25:38 -1000 Subject: [PATCH] added a stress test (multiple simultaneous download) + section in tests/dune --- tests/dl-stress.expect | 16 ++++++++++++++++ tests/dune | 33 ++++++++++++++++++++++++++++++--- tests/stress.sh | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/dl-stress.expect create mode 100755 tests/stress.sh diff --git a/tests/dl-stress.expect b/tests/dl-stress.expect new file mode 100644 index 00000000..508ed771 --- /dev/null +++ b/tests/dl-stress.expect @@ -0,0 +1,16 @@ +serve directory . on http://127.0.0.1:8088 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 +52428800 diff --git a/tests/dune b/tests/dune index 53bf6ea5..25cc3826 100644 --- a/tests/dune +++ b/tests/dune @@ -1,3 +1,5 @@ +; echo +;===== (rule (targets echo1.out) @@ -13,6 +15,9 @@ (enabled_if (= %{system} "linux")) (action (diff echo1.expect echo1.out))) +; sse +; ==== + (rule (targets sse_count.out) (deps (:bin ../examples/sse_server.exe)) @@ -27,6 +32,15 @@ (enabled_if (= %{system} "linux")) (action (diff sse_count.expect sse_count.out))) +; chunked +;======== + +(rule + (targets foo_50) + (enabled_if (= %{system} "linux")) + (action + (bash "dd if=/dev/zero of=%{targets} bs=1M count=50"))) + (rule (targets upload-out) (deps (:bin ../src/bin/http_of_dir.exe) foo_50) @@ -42,6 +56,7 @@ (enabled_if (= %{system} "linux")) (action (diff upload-out.expect upload-out))) + (rule (targets dl-out) (deps (:bin ../src/bin/http_of_dir.exe) foo_50) @@ -57,8 +72,20 @@ (enabled_if (= %{system} "linux")) (action (diff dl-out.expect dl-out))) +; stress +;======= + (rule - (targets foo_50) + (targets dl-stress) + (deps (:bin ../src/bin/http_of_dir.exe) foo_50) + (locks /port) + (package tiny_httpd) (enabled_if (= %{system} "linux")) - (action - (bash "dd if=/dev/zero of=%{targets} bs=1M count=50"))) + (action (with-stdout-to %{targets} + (run ./stress.sh %{bin} 15)))) + +(rule + (alias runtest) + (package tiny_httpd) + (enabled_if (= %{system} "linux")) + (action (diff dl-stress.expect dl-stress))) diff --git a/tests/stress.sh b/tests/stress.sh new file mode 100755 index 00000000..2735fab8 --- /dev/null +++ b/tests/stress.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +SERVER=$1 +PORT=8088 +"$SERVER" . -p $PORT & +PID=$! + +url=http://localhost:${PORT}/foo_50 +nb=$2 +sleep_time=0 + +for (( c=1; c<=$nb; c++ )); do + f=$(mktemp) + (curl -s $url > $f; stat -c %s $f; rm $f) & + PIDS[$c]=$! + + sleep $sleep_time +done + +#echo ${PIDS[@]} +wait ${PIDS[@]} + +kill $PID