From dc72dad5db5e33564e89cd946f6950bcc84006e5 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 09:30:41 -0500 Subject: [PATCH 01/11] revert: remove timeout handling for now This reverts commit 6536bfeeb3506db4ec32798a9a813670b5214fb0. --- src/Tiny_httpd.ml | 67 +++++----------------------------------------- src/Tiny_httpd.mli | 12 ++------- 2 files changed, 9 insertions(+), 70 deletions(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index 508bff26..f0f95b6f 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -83,37 +83,6 @@ module Byte_stream = struct let of_chan = of_chan_ ~close:close_in let of_chan_close_noerr = of_chan_ ~close:close_in_noerr - exception Timeout - - let of_descr_ ?(timeout=(-1.0)) ~close ic : t = - let i = ref 0 in - let len = ref 0 in - let buf = Bytes.make 4096 ' ' in - { bs_fill_buf=(fun () -> - if !i >= !len then ( - i := 0; - - let rec wait() = - let to_read,_,_ = Unix.select [ic] [] [] timeout in - if to_read = [] then raise Timeout; - read() - and read() = - try len := Unix.read ic buf 0 (Bytes.length buf) - with - | Unix.Unix_error (EAGAIN, _, _) -> read() - | Unix.Unix_error (EWOULDBLOCK, _, _) -> - (* FIXME: we should decrease the timeout by however long was spent in [select] *) - wait() - in - wait() - ); - buf, !i,!len - !i); - bs_consume=(fun n -> i := !i + n); - bs_close=(fun () -> close ic) - } - - let of_descr = of_descr_ ~close:Unix.close - let rec iter f (self:t) : unit = let s, i, len = self.bs_fill_buf () in if len=0 then ( @@ -542,9 +511,6 @@ module Request = struct headers; body=()}) with | End_of_file | Sys_error _ -> Ok None - | Byte_stream.Timeout -> - _debug (fun k -> k"Timeout"); - Ok None | Bad_req (c,s) -> Error (c,s) | e -> Error (400, Printexc.to_string e) @@ -710,14 +676,13 @@ end module Sem_ = struct type t = { mutable n : int; - max: int; mutex : Mutex.t; cond : Condition.t; } let create n = if n <= 0 then invalid_arg "Semaphore.create"; - { n; max=n; mutex=Mutex.create(); cond=Condition.create(); } + { n; mutex=Mutex.create(); cond=Condition.create(); } let acquire m t = Mutex.lock t.mutex; @@ -734,8 +699,6 @@ module Sem_ = struct t.n <- t.n + m; Condition.broadcast t.cond; Mutex.unlock t.mutex - - let num_acquired self = self.max - self.n end module Route = struct @@ -851,9 +814,6 @@ type t = { sem_max_connections: Sem_.t; (* semaphore to restrict the number of active concurrent connections *) - max_keep_alive: float; - (* maximum time in second before closing the client connections *) - new_thread: (unit -> unit) -> unit; (* a function to run the given callback in a separate thread (or thread pool) *) @@ -880,10 +840,6 @@ type t = { let addr self = self.addr let port self = self.port -let active_connections self = - (* -1 because we decrease the semaphore before Unix.accept *) - Sem_.num_acquired self.sem_max_connections - 1 - let add_decode_request_cb self f = self.cb_decode_req <- f :: self.cb_decode_req let add_encode_response_cb self f = self.cb_encode_resp <- f :: self.cb_encode_resp let set_top_handler self f = self.handler <- f @@ -992,14 +948,13 @@ let add_route_server_sent_handler ?accept self route f = let create ?(masksigpipe=true) ?(max_connections=32) - ?(max_keep_alive=(-1.0)) ?(new_thread=(fun f -> ignore (Thread.create f () : Thread.t))) ?(addr="127.0.0.1") ?(port=8080) ?sock () : t = let handler _req = Response.fail ~code:404 "no top handler" in let max_connections = max 4 max_connections in { new_thread; addr; port; sock; masksigpipe; handler; running= true; sem_max_connections=Sem_.create max_connections; - path_handlers=[]; max_keep_alive; + path_handlers=[]; cb_encode_resp=[]; cb_decode_req=[]; } @@ -1015,11 +970,10 @@ let find_map f l = in aux f l let handle_client_ (self:t) (client_sock:Unix.file_descr) : unit = - let write_sock = Unix.dup client_sock in - let _ = Unix.set_nonblock client_sock in - let oc = Unix.out_channel_of_descr write_sock in + let ic = Unix.in_channel_of_descr client_sock in + let oc = Unix.out_channel_of_descr client_sock in let buf = Buf_.create() in - let is = Byte_stream.of_descr ~timeout:self.max_keep_alive client_sock in + let is = Byte_stream.of_chan ic in let continue = ref true in while !continue && self.running do _debug (fun k->k "read next request"); @@ -1133,24 +1087,17 @@ let run (self:t) : (unit,_) result = end; while self.running do (* limit concurrency *) + Sem_.acquire 1 self.sem_max_connections; try - Sem_.acquire 1 self.sem_max_connections; let client_sock, _ = Unix.accept sock in self.new_thread (fun () -> try handle_client_ self client_sock; Sem_.release 1 self.sem_max_connections; - _debug (fun k -> k - "closing inactive connections (%d connections active)" - (active_connections self)) - with - | e -> + with e -> (try Unix.close client_sock with _ -> ()); Sem_.release 1 self.sem_max_connections; - _debug (fun k -> k - "closing connections on error (%d connections active)" - (active_connections self)); raise e ); with e -> diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index 1e7069bf..77610de7 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -434,7 +434,6 @@ type t val create : ?masksigpipe:bool -> ?max_connections:int -> - ?max_keep_alive:float -> ?new_thread:((unit -> unit) -> unit) -> ?addr:string -> ?port:int -> @@ -454,11 +453,7 @@ val create : new client connection. By default it is {!Thread.create} but one could use a thread pool instead. - @param max_connections maximum number of simultaneous connections. Default 32. - @param max_keep_alive maximum number of seconds a thread in maintened for - a client with nothing to read. Default: -1.0, meaning threads are maintened - until client close the socket. - This parameter exists since 0.11. + @param max_connections maximum number of simultaneous connections. @param addr address (IPv4 or IPv6) to listen on. Default ["127.0.0.1"]. @param port to listen on. Default [8080]. @param sock an existing socket given to the server to listen on, e.g. by @@ -477,10 +472,6 @@ val is_ipv6 : t -> bool val port : t -> int (** Port on which the server listens. *) -val active_connections : t -> int -(** number of currently opened connections with a client. - @since 0.11 *) - val add_decode_request_cb : t -> (unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> unit @@ -648,3 +639,4 @@ val _debug : ((('a, out_channel, unit, unit, unit, unit) format6 -> 'a) -> unit) val _enable_debug: bool -> unit (**/**) + From b5269f5b054bf307e701fb59881f2bb652904f61 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 09:46:33 -0500 Subject: [PATCH 02/11] small test --- tests/echo1.expect | 9 +++++++++ tests/echo1.sh | 8 ++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/echo1.expect create mode 100755 tests/echo1.sh diff --git a/tests/echo1.expect b/tests/echo1.expect new file mode 100644 index 00000000..7579fba1 --- /dev/null +++ b/tests/echo1.expect @@ -0,0 +1,9 @@ +listening on http://127.0.0.1:8083 +echo: +{meth=GET; host=localhost:8083; + headers=[user-agent: test + accept: */* + host: localhost:8083]; + path="/echo/?a=b&c=d"; body=""; path_components=["echo"]; + query=["c","d";"a","b"]} +(query: "c" = "d";"a" = "b") diff --git a/tests/echo1.sh b/tests/echo1.sh new file mode 100755 index 00000000..e5a20500 --- /dev/null +++ b/tests/echo1.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +ECHO=$1 + +"$ECHO" -p 8083 & +sleep 0.1 +curl -N 'http://localhost:8083/echo/?a=b&c=d' -H user-agent:test +kill %1 From 89344f46f0fcc2280991a11d2fd63aaa471670d2 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 10:01:55 -0500 Subject: [PATCH 03/11] feat(server-sent): add a `close()` function --- src/Tiny_httpd.ml | 5 ++++- src/Tiny_httpd.mli | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index f0f95b6f..07956191 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -801,6 +801,7 @@ module type SERVER_SENT_GENERATOR = sig ?retry:string -> data:string -> unit -> unit + val close : unit -> unit end type server_sent_generator = (module SERVER_SENT_GENERATOR) @@ -940,8 +941,10 @@ let add_route_server_sent_handler ?accept self route f = send_response_idempotent_() ) let send_event = send_event + let close () = raise Exit end in - f req (module SSG : SERVER_SENT_GENERATOR); + try f req (module SSG : SERVER_SENT_GENERATOR); + with Exit -> close_out oc in add_route_handler_ self ?accept ~meth:`GET route ~tr_req f diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index 77610de7..ec8dee10 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -595,6 +595,10 @@ module type SERVER_SENT_GENERATOR = sig unit -> unit (** Send an event from the server. If data is a multiline string, it will be sent on separate "data:" lines. *) + + val close : unit -> unit + (** Close connection. + @since 0.11 *) end type server_sent_generator = (module SERVER_SENT_GENERATOR) From c8982c8836744d182c21640e3158317d9d883dbc Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 10:02:04 -0500 Subject: [PATCH 04/11] move echo from src/examples/ to examples/ --- echo.sh | 2 +- examples/dune | 6 ++++++ {src/examples => examples}/echo.ml | 0 examples/sse_server.ml | 8 ++++++++ src/examples/dune | 5 ----- 5 files changed, 15 insertions(+), 6 deletions(-) rename {src/examples => examples}/echo.ml (100%) delete mode 100644 src/examples/dune diff --git a/echo.sh b/echo.sh index a7d0acd1..c97ce729 100755 --- a/echo.sh +++ b/echo.sh @@ -1,2 +1,2 @@ #!/bin/sh -exec dune exec "src/examples/echo.exe" -- $@ +exec dune exec "examples/echo.exe" -- $@ diff --git a/examples/dune b/examples/dune index f623f8d0..83b0aa84 100644 --- a/examples/dune +++ b/examples/dune @@ -9,6 +9,12 @@ (modules sse_client) (libraries unix)) +(executable + (name echo) + (flags :standard -warn-error -a+8) + (modules echo) + (libraries tiny_httpd tiny_httpd_camlzip)) + (rule (targets test_output.txt) (deps (:script ./run_test.sh) ./sse_client.exe ./sse_server.exe) diff --git a/src/examples/echo.ml b/examples/echo.ml similarity index 100% rename from src/examples/echo.ml rename to examples/echo.ml diff --git a/examples/sse_server.ml b/examples/sse_server.ml index cf30c95e..fb1ede07 100644 --- a/examples/sse_server.ml +++ b/examples/sse_server.ml @@ -44,6 +44,14 @@ let () = Unix.sleepf 0.1; done; ); + S.add_route_server_sent_handler server S.Route.(exact "count" @/ int @/ return) + (fun n _req (module EV : S.SERVER_SENT_GENERATOR) -> + for i=0 to n do + EV.send_event ~data:(string_of_int i) (); + Unix.sleepf 0.1; + done; + EV.close(); + ); Printf.printf "listening on http://localhost:%d/\n%!" (S.port server); match S.run server with diff --git a/src/examples/dune b/src/examples/dune deleted file mode 100644 index 409ea47e..00000000 --- a/src/examples/dune +++ /dev/null @@ -1,5 +0,0 @@ - -(executables - (names echo) - (flags :standard -warn-error -a+8) - (libraries tiny_httpd tiny_httpd_camlzip)) From ed4c73152372311d6152b86ab69ec3ac23b68280 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 10:02:32 -0500 Subject: [PATCH 05/11] more tests, including a small sse count --- tests/dune | 20 ++++++++++++++++++++ tests/sse_count.expect | 23 +++++++++++++++++++++++ tests/sse_count.sh | 9 +++++++++ tiny_httpd.opam | 1 + 4 files changed, 53 insertions(+) create mode 100644 tests/dune create mode 100644 tests/sse_count.expect create mode 100755 tests/sse_count.sh diff --git a/tests/dune b/tests/dune new file mode 100644 index 00000000..3303531b --- /dev/null +++ b/tests/dune @@ -0,0 +1,20 @@ + +(rule + (targets echo1.out) + (deps (:bin ../examples/echo.exe)) + (locks /port) + (action (with-stdout-to %{targets} (run ./echo1.sh %{bin})))) + +(rule + (alias runtest) + (action (diff echo1.expect echo1.out))) + +(rule + (targets sse_count.out) + (deps (:bin ../examples/sse_server.exe)) + (locks /port) + (action (with-stdout-to %{targets} (run ./sse_count.sh %{bin})))) + +(rule + (alias runtest) + (action (diff sse_count.expect sse_count.out))) diff --git a/tests/sse_count.expect b/tests/sse_count.expect new file mode 100644 index 00000000..19e6a28d --- /dev/null +++ b/tests/sse_count.expect @@ -0,0 +1,23 @@ +listening on http://localhost:8083/ +data: 0 + +data: 1 + +data: 2 + +data: 3 + +data: 4 + +data: 5 + +data: 6 + +data: 7 + +data: 8 + +data: 9 + +data: 10 + diff --git a/tests/sse_count.sh b/tests/sse_count.sh new file mode 100755 index 00000000..89e0aa0b --- /dev/null +++ b/tests/sse_count.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +SSE_SERVER=$1 + +"$SSE_SERVER" -p 8083 & +sleep 0.1 + +curl -N 'http://localhost:8083/count/10' -H user-agent:test +kill %1 diff --git a/tiny_httpd.opam b/tiny_httpd.opam index cbc33ccf..90827ac6 100644 --- a/tiny_httpd.opam +++ b/tiny_httpd.opam @@ -15,6 +15,7 @@ depends: [ "ocaml" { >= "4.04.0" } "odoc" {with-doc} "qtest" { >= "2.9" & with-test} + "conf-curl" {with-test} "qcheck" {with-test & >= "0.9" } "ounit2" {with-test} "ptime" {with-test} From 69c16b0a5d21291adcdb54c5454d5a05bbd6761d Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 10:14:07 -0500 Subject: [PATCH 06/11] add an upload test --- Makefile | 5 ++++- tests/.gitignore | 1 + tests/dune | 11 +++++++++++ tests/upload-out.expect | 2 ++ tests/upload_chunked.sh | 13 +++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/.gitignore create mode 100644 tests/upload-out.expect create mode 100755 tests/upload_chunked.sh diff --git a/Makefile b/Makefile index 39fceab8..c586a411 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,12 @@ all: build test build: @dune build @install -test: +test: tests/foo_50 @dune runtest --no-buffer --force +tests/foo_50: + dd if=/dev/zero of=$@ bs=1M count=50 + clean: @dune clean diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..7552a656 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +foo_50 diff --git a/tests/dune b/tests/dune index 3303531b..6c270bbd 100644 --- a/tests/dune +++ b/tests/dune @@ -18,3 +18,14 @@ (rule (alias runtest) (action (diff sse_count.expect sse_count.out))) + +(rule + (targets upload-out) + (deps (:bin ../src/bin/http_of_dir.exe) foo_50) + (locks /port) + (action (with-stdout-to %{targets} + (run ./upload_chunked.sh %{bin})))) + +(rule + (alias runtest) + (action (diff upload-out.expect upload-out))) diff --git a/tests/upload-out.expect b/tests/upload-out.expect new file mode 100644 index 00000000..0ef0335f --- /dev/null +++ b/tests/upload-out.expect @@ -0,0 +1,2 @@ +serve directory . on http://127.0.0.1:8083 +upload successful 0 0 52428800 data diff --git a/tests/upload_chunked.sh b/tests/upload_chunked.sh new file mode 100755 index 00000000..a3d42563 --- /dev/null +++ b/tests/upload_chunked.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +rm data + +SERVER=$1 +"$SERVER" . -p 8083 --upload --max-upload 100000000000 & + +sleep 0.1 + +cat foo_50 | curl -N -X PUT http://localhost:8083/data --data-binary @- -H 'Transfer-Encoding: chunked' + +kill %1 +wc data From 8813dd64f9aa41be7fa1df85131382c4bff0f997 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 10:18:42 -0500 Subject: [PATCH 07/11] add test for download --- tests/dl-out.expect | 2 ++ tests/download_chunked.sh | 12 ++++++++++++ tests/dune | 11 +++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/dl-out.expect create mode 100755 tests/download_chunked.sh diff --git a/tests/dl-out.expect b/tests/dl-out.expect new file mode 100644 index 00000000..221be93f --- /dev/null +++ b/tests/dl-out.expect @@ -0,0 +1,2 @@ +serve directory . on http://127.0.0.1:8083 + 0 0 52428800 data2 diff --git a/tests/download_chunked.sh b/tests/download_chunked.sh new file mode 100755 index 00000000..f28d8234 --- /dev/null +++ b/tests/download_chunked.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +SERVER=$1 +"$SERVER" . -p 8083 & + +sleep 0.1 + +curl -N 'http://localhost:8083/foo_50' -o data2 \ + -H 'Tranfer-encoding: chunked' + +kill %1 +wc data2 diff --git a/tests/dune b/tests/dune index 6c270bbd..37621ada 100644 --- a/tests/dune +++ b/tests/dune @@ -29,3 +29,14 @@ (rule (alias runtest) (action (diff upload-out.expect upload-out))) + +(rule + (targets dl-out) + (deps (:bin ../src/bin/http_of_dir.exe) foo_50) + (locks /port) + (action (with-stdout-to %{targets} + (run ./download_chunked.sh %{bin})))) + +(rule + (alias runtest) + (action (diff dl-out.expect dl-out))) From 8d1a71e625b9f5ec491d500551f2ff0039c877db Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 11:00:25 -0500 Subject: [PATCH 08/11] try to use conf-libcurl --- tiny_httpd.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiny_httpd.opam b/tiny_httpd.opam index 90827ac6..8a0df3ff 100644 --- a/tiny_httpd.opam +++ b/tiny_httpd.opam @@ -15,7 +15,7 @@ depends: [ "ocaml" { >= "4.04.0" } "odoc" {with-doc} "qtest" { >= "2.9" & with-test} - "conf-curl" {with-test} + "conf-libcurl" {with-test} "qcheck" {with-test & >= "0.9" } "ounit2" {with-test} "ptime" {with-test} From b4667e9686dd3186383007017f3338abd39820da Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 13:20:18 -0500 Subject: [PATCH 09/11] test: fix production of data file --- Makefile | 5 +---- tests/dune | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c586a411..39fceab8 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,9 @@ all: build test build: @dune build @install -test: tests/foo_50 +test: @dune runtest --no-buffer --force -tests/foo_50: - dd if=/dev/zero of=$@ bs=1M count=50 - clean: @dune clean diff --git a/tests/dune b/tests/dune index 37621ada..48277535 100644 --- a/tests/dune +++ b/tests/dune @@ -40,3 +40,9 @@ (rule (alias runtest) (action (diff dl-out.expect dl-out))) + + +(rule + (targets foo_50) + (action + (bash "dd if=/dev/zero of=%{targets} bs=1M count=50"))) From bcce3e22dc26ec7f423fa313c35fce412d9ccb79 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 16:08:16 -0500 Subject: [PATCH 10/11] CI: test only on linux --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ef715a5..6a1cdf9e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,3 +18,4 @@ jobs: - run: opam install -t . --deps-only - run: opam exec -- dune build - run: opam exec -- dune runtest + if: ${{ matrix.operating-system == 'unbuntu-latest' }} From b468854626f53bfe1704cd491676bb18c2e71cf8 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 11 Dec 2021 16:25:34 -0500 Subject: [PATCH 11/11] test: use different ports for each test, run some targets only on linux --- .github/workflows/main.yml | 2 +- tests/dl-out.expect | 2 +- tests/download_chunked.sh | 5 +++-- tests/dune | 4 ++++ tests/echo1.expect | 6 +++--- tests/echo1.sh | 5 +++-- tests/sse_count.expect | 2 +- tests/sse_count.sh | 5 +++-- tests/upload-out.expect | 2 +- tests/upload_chunked.sh | 6 ++++-- 10 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a1cdf9e..bdbe0ab7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,6 @@ jobs: - run: opam pin -n . - run: opam depext -yt tiny_httpd tiny_httpd_camlzip - run: opam install -t . --deps-only - - run: opam exec -- dune build + - run: opam exec -- dune build @install - run: opam exec -- dune runtest if: ${{ matrix.operating-system == 'unbuntu-latest' }} diff --git a/tests/dl-out.expect b/tests/dl-out.expect index 221be93f..d0e79081 100644 --- a/tests/dl-out.expect +++ b/tests/dl-out.expect @@ -1,2 +1,2 @@ -serve directory . on http://127.0.0.1:8083 +serve directory . on http://127.0.0.1:8084 0 0 52428800 data2 diff --git a/tests/download_chunked.sh b/tests/download_chunked.sh index f28d8234..6d8cbde6 100755 --- a/tests/download_chunked.sh +++ b/tests/download_chunked.sh @@ -1,11 +1,12 @@ #!/usr/bin/env sh SERVER=$1 -"$SERVER" . -p 8083 & +PORT=8084 +"$SERVER" . -p $PORT & sleep 0.1 -curl -N 'http://localhost:8083/foo_50' -o data2 \ +curl -N "http://localhost:${PORT}/foo_50" -o data2 \ -H 'Tranfer-encoding: chunked' kill %1 diff --git a/tests/dune b/tests/dune index 48277535..363933bf 100644 --- a/tests/dune +++ b/tests/dune @@ -3,6 +3,7 @@ (targets echo1.out) (deps (:bin ../examples/echo.exe)) (locks /port) + (enabled_if (= %{system} "linux")) (action (with-stdout-to %{targets} (run ./echo1.sh %{bin})))) (rule @@ -13,6 +14,7 @@ (targets sse_count.out) (deps (:bin ../examples/sse_server.exe)) (locks /port) + (enabled_if (= %{system} "linux")) (action (with-stdout-to %{targets} (run ./sse_count.sh %{bin})))) (rule @@ -23,6 +25,7 @@ (targets upload-out) (deps (:bin ../src/bin/http_of_dir.exe) foo_50) (locks /port) + (enabled_if (= %{system} "linux")) (action (with-stdout-to %{targets} (run ./upload_chunked.sh %{bin})))) @@ -34,6 +37,7 @@ (targets dl-out) (deps (:bin ../src/bin/http_of_dir.exe) foo_50) (locks /port) + (enabled_if (= %{system} "linux")) (action (with-stdout-to %{targets} (run ./download_chunked.sh %{bin})))) diff --git a/tests/echo1.expect b/tests/echo1.expect index 7579fba1..541334f7 100644 --- a/tests/echo1.expect +++ b/tests/echo1.expect @@ -1,9 +1,9 @@ -listening on http://127.0.0.1:8083 +listening on http://127.0.0.1:8085 echo: -{meth=GET; host=localhost:8083; +{meth=GET; host=localhost:8085; headers=[user-agent: test accept: */* - host: localhost:8083]; + host: localhost:8085]; path="/echo/?a=b&c=d"; body=""; path_components=["echo"]; query=["c","d";"a","b"]} (query: "c" = "d";"a" = "b") diff --git a/tests/echo1.sh b/tests/echo1.sh index e5a20500..5cad7b60 100755 --- a/tests/echo1.sh +++ b/tests/echo1.sh @@ -1,8 +1,9 @@ #!/usr/bin/env sh ECHO=$1 +PORT=8085 -"$ECHO" -p 8083 & +"$ECHO" -p $PORT & sleep 0.1 -curl -N 'http://localhost:8083/echo/?a=b&c=d' -H user-agent:test +curl -N "http://localhost:${PORT}/echo/?a=b&c=d" -H user-agent:test kill %1 diff --git a/tests/sse_count.expect b/tests/sse_count.expect index 19e6a28d..193cc0b9 100644 --- a/tests/sse_count.expect +++ b/tests/sse_count.expect @@ -1,4 +1,4 @@ -listening on http://localhost:8083/ +listening on http://localhost:8086/ data: 0 data: 1 diff --git a/tests/sse_count.sh b/tests/sse_count.sh index 89e0aa0b..6010ed37 100755 --- a/tests/sse_count.sh +++ b/tests/sse_count.sh @@ -1,9 +1,10 @@ #!/usr/bin/env sh SSE_SERVER=$1 +PORT=8086 -"$SSE_SERVER" -p 8083 & +"$SSE_SERVER" -p $PORT & sleep 0.1 -curl -N 'http://localhost:8083/count/10' -H user-agent:test +curl -N "http://localhost:${PORT}/count/10" -H user-agent:test kill %1 diff --git a/tests/upload-out.expect b/tests/upload-out.expect index 0ef0335f..7c5ca0cc 100644 --- a/tests/upload-out.expect +++ b/tests/upload-out.expect @@ -1,2 +1,2 @@ -serve directory . on http://127.0.0.1:8083 +serve directory . on http://127.0.0.1:8087 upload successful 0 0 52428800 data diff --git a/tests/upload_chunked.sh b/tests/upload_chunked.sh index a3d42563..ca64ac8a 100755 --- a/tests/upload_chunked.sh +++ b/tests/upload_chunked.sh @@ -3,11 +3,13 @@ rm data SERVER=$1 -"$SERVER" . -p 8083 --upload --max-upload 100000000000 & +PORT=8087 + +"$SERVER" . -p $PORT --upload --max-upload 100000000000 & sleep 0.1 -cat foo_50 | curl -N -X PUT http://localhost:8083/data --data-binary @- -H 'Transfer-Encoding: chunked' +cat foo_50 | curl -N -X PUT http://localhost:$PORT/data --data-binary @- -H 'Transfer-Encoding: chunked' kill %1 wc data