From 2d74ead0b9773ea2c321a745750eb9b4ba3d08d3 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 15:56:45 +0100 Subject: [PATCH 01/14] Test 1-hello --- dune-project | 2 +- test/cram/1-hello.t | 4 ++++ test/cram/README.md | 5 +++++ test/cram/dune | 10 ++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/cram/1-hello.t create mode 100644 test/cram/README.md create mode 100644 test/cram/dune diff --git a/dune-project b/dune-project index 45acd3f0..37f995d6 100644 --- a/dune-project +++ b/dune-project @@ -1 +1 @@ -(lang dune 2.7) +(lang dune 3.0) diff --git a/test/cram/1-hello.t b/test/cram/1-hello.t new file mode 100644 index 00000000..dd024635 --- /dev/null +++ b/test/cram/1-hello.t @@ -0,0 +1,4 @@ + $ hello &> /dev/null & + $ $CURL localhost:8080 + Good morning, world! + $ pkill -P $$ diff --git a/test/cram/README.md b/test/cram/README.md new file mode 100644 index 00000000..cdeeb1bb --- /dev/null +++ b/test/cram/README.md @@ -0,0 +1,5 @@ +# Cram tests guidelines +* Make the example available via the dune file, e.g. `env _ (binaries ../../example/1-hello/hello.exe)))` +* Use `$CURL` instead of `curl` as we need retries in case the server is not yet available. +* Pipe the output of the server to `/dev/null` as it includes timestamps. +* Run `pkill -P $$` to kill the server at the end of the test. diff --git a/test/cram/dune b/test/cram/dune new file mode 100644 index 00000000..befb7b4b --- /dev/null +++ b/test/cram/dune @@ -0,0 +1,10 @@ +(cram + (deps %{bin:hello})) + +(env + (_ + (env-vars + ; --silent: Remove progress bar and error messages from retries + ; --retry 5 --retry-connrefused: retry in case curl is run before the server is available + (CURL "curl --silent --retry 2 --retry-connrefused")) + (binaries ../../example/1-hello/hello.exe))) From 0c3990a606f2137ab5749401c2a41ac5dcd9e363 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 15:57:47 +0100 Subject: [PATCH 02/14] Test 2-middleware --- test/cram/2-middleware.t | 4 ++++ test/cram/dune | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/cram/2-middleware.t diff --git a/test/cram/2-middleware.t b/test/cram/2-middleware.t new file mode 100644 index 00000000..5edbc4f5 --- /dev/null +++ b/test/cram/2-middleware.t @@ -0,0 +1,4 @@ + $ middleware &> /dev/null & + $ $CURL localhost:8080 + Good morning, world! + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index befb7b4b..b8c5f8f0 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,5 @@ (cram - (deps %{bin:hello})) + (deps %{bin:hello} %{bin:middleware})) (env (_ @@ -7,4 +7,6 @@ ; --silent: Remove progress bar and error messages from retries ; --retry 5 --retry-connrefused: retry in case curl is run before the server is available (CURL "curl --silent --retry 2 --retry-connrefused")) - (binaries ../../example/1-hello/hello.exe))) + (binaries + ../../example/1-hello/hello.exe + ../../example/2-middleware/middleware.exe))) From 50f8131cfda794d0e2692b11d9b2d2c0a984e481 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:00:14 +0100 Subject: [PATCH 03/14] Test 3-router --- test/cram/3-router.t | 4 ++++ test/cram/dune | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/cram/3-router.t diff --git a/test/cram/3-router.t b/test/cram/3-router.t new file mode 100644 index 00000000..13823ca4 --- /dev/null +++ b/test/cram/3-router.t @@ -0,0 +1,4 @@ + $ router &> /dev/null & + $ $CURL localhost:8080/echo/hello-world + hello-world + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index b8c5f8f0..884db5d0 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,5 @@ (cram - (deps %{bin:hello} %{bin:middleware})) + (deps %{bin:hello} %{bin:middleware} %{bin:router})) (env (_ @@ -9,4 +9,5 @@ (CURL "curl --silent --retry 2 --retry-connrefused")) (binaries ../../example/1-hello/hello.exe - ../../example/2-middleware/middleware.exe))) + ../../example/2-middleware/middleware.exe + ../../example/3-router/router.exe))) From e74770f04dc156346c36438c7da15a4a742d6c58 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:14:31 +0100 Subject: [PATCH 04/14] Test 4-counter --- example/4-counter/counter.ml | 2 +- test/cram/4-counter.t | 6 ++++++ test/cram/dune | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 test/cram/4-counter.t diff --git a/example/4-counter/counter.ml b/example/4-counter/counter.ml index 2a1d10ac..bf5559e0 100644 --- a/example/4-counter/counter.ml +++ b/example/4-counter/counter.ml @@ -10,5 +10,5 @@ let () = @@ count_requests @@ Dream.router [ Dream.get "/" (fun _ -> - Dream.html (Printf.sprintf "Saw %i request(s)!" !count)); + Dream.html (Printf.sprintf "Responding to the %i. request!" !count)); ] diff --git a/test/cram/4-counter.t b/test/cram/4-counter.t new file mode 100644 index 00000000..26ceb5b5 --- /dev/null +++ b/test/cram/4-counter.t @@ -0,0 +1,6 @@ + $ counter &> /dev/null & + $ $CURL localhost:8080 + Responding to the 1. request! + $ $CURL localhost:8080 + Responding to the 2. request! + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index 884db5d0..3f92fef2 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,5 @@ (cram - (deps %{bin:hello} %{bin:middleware} %{bin:router})) + (deps %{bin:hello} %{bin:middleware} %{bin:router} %{bin:counter})) (env (_ @@ -10,4 +10,5 @@ (binaries ../../example/1-hello/hello.exe ../../example/2-middleware/middleware.exe - ../../example/3-router/router.exe))) + ../../example/3-router/router.exe + ../../example/4-counter/counter.exe))) From 4fa23d75c60f6336b1e085351034163f01cd0b61 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:22:15 +0100 Subject: [PATCH 05/14] Test 5-promise --- test/cram/5-promise.t | 7 +++++++ test/cram/README.md | 1 + test/cram/dune | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/cram/5-promise.t diff --git a/test/cram/5-promise.t b/test/cram/5-promise.t new file mode 100644 index 00000000..e4d5ee3f --- /dev/null +++ b/test/cram/5-promise.t @@ -0,0 +1,7 @@ + $ promise &> /dev/null & + $ $CURL localhost:8080 + 0 request(s) successful
0 request(s) failed + $ curl --no-progress-meter localhost:8080/fail + $ $CURL localhost:8080 + 1 request(s) successful
1 request(s) failed + $ pkill -P $$ diff --git a/test/cram/README.md b/test/cram/README.md index cdeeb1bb..8eb67c92 100644 --- a/test/cram/README.md +++ b/test/cram/README.md @@ -3,3 +3,4 @@ * Use `$CURL` instead of `curl` as we need retries in case the server is not yet available. * Pipe the output of the server to `/dev/null` as it includes timestamps. * Run `pkill -P $$` to kill the server at the end of the test. +* Execute only one test at a time (e.g. `dune runtest -j1`) as the tests all use the same port diff --git a/test/cram/dune b/test/cram/dune index 3f92fef2..b40a377f 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,10 @@ (cram - (deps %{bin:hello} %{bin:middleware} %{bin:router} %{bin:counter})) + (deps + %{bin:hello} + %{bin:middleware} + %{bin:router} + %{bin:counter} + %{bin:promise})) (env (_ @@ -11,4 +16,5 @@ ../../example/1-hello/hello.exe ../../example/2-middleware/middleware.exe ../../example/3-router/router.exe - ../../example/4-counter/counter.exe))) + ../../example/4-counter/counter.exe + ../../example/5-promise/promise.exe))) From f5d351a3f48f36cc5f8139521595b1e7828e7c3c Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:27:27 +0100 Subject: [PATCH 06/14] Test 6-echo --- test/cram/6-echo.t | 4 ++++ test/cram/dune | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/cram/6-echo.t diff --git a/test/cram/6-echo.t b/test/cram/6-echo.t new file mode 100644 index 00000000..e5f8cf41 --- /dev/null +++ b/test/cram/6-echo.t @@ -0,0 +1,4 @@ + $ echo-server &> /dev/null & + $ $CURL localhost:8080/echo --data "Hello, world!" + Hello, world! + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index b40a377f..c93f6fde 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -4,7 +4,8 @@ %{bin:middleware} %{bin:router} %{bin:counter} - %{bin:promise})) + %{bin:promise} + %{bin:echo-server})) (env (_ @@ -17,4 +18,5 @@ ../../example/2-middleware/middleware.exe ../../example/3-router/router.exe ../../example/4-counter/counter.exe - ../../example/5-promise/promise.exe))) + ../../example/5-promise/promise.exe + (../../example/6-echo/echo.exe as echo-server)))) From 7d5c872435c7d06771780ae67dcb5359290aa947 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Sun, 18 May 2025 13:19:26 +0100 Subject: [PATCH 07/14] Fix 7 through d and f --- test/cram/7-template.t | 9 ++ test/cram/8-debug.t | 298 +++++++++++++++++++++++++++++++++++++++++ test/cram/9-error.t | 46 +++++++ test/cram/a-log.t | 5 + test/cram/b-session.t | 6 + test/cram/c-cookie.t | 7 + test/cram/d-form.t | 31 +++++ test/cram/dune | 35 ++++- test/cram/f-static.t | 9 ++ 9 files changed, 444 insertions(+), 2 deletions(-) create mode 100644 test/cram/7-template.t create mode 100644 test/cram/8-debug.t create mode 100644 test/cram/9-error.t create mode 100644 test/cram/a-log.t create mode 100644 test/cram/b-session.t create mode 100644 test/cram/c-cookie.t create mode 100644 test/cram/d-form.t create mode 100644 test/cram/f-static.t diff --git a/test/cram/7-template.t b/test/cram/7-template.t new file mode 100644 index 00000000..ccab89a8 --- /dev/null +++ b/test/cram/7-template.t @@ -0,0 +1,9 @@ + $ template &> /dev/null & + $ $CURL localhost:8080/hello-world + + +

The URL parameter was hello-world!

+ + + + $ pkill -P $$ diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t new file mode 100644 index 00000000..8a703323 --- /dev/null +++ b/test/cram/8-debug.t @@ -0,0 +1,298 @@ + $ debug &> /dev/null & + $ $CURL localhost:8080/bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + + + + + + 400 Bad Request + + + +

An error occured!

+

400 Bad Request

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
400 Bad Request
+  
+  From: Application
+  Blame: Client
+  Severity: Warning
+  
+  Client: ::1:
+  
+  GET /bad
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + + + + + + 500 Internal Server Error + + + +

An error occured!

+

500 Internal Server Error

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
Failure("The Web app failed!")
+  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
+  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  
+  From: Application
+  Blame: Server
+  Severity: Error
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + + + + + + + 500 Internal Server Error + + + +

An error occured!

+

500 Internal Server Error

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
Failure("The Web app failed!")
+  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
+  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  
+  From: Application
+  Blame: Server
+  Severity: Error
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + + + + + + + 500 Internal Server Error + + + +

An error occured!

+

500 Internal Server Error

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
Failure("The Web app failed!")
+  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
+  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  
+  From: Application
+  Blame: Server
+  Severity: Error
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + $ pkill -P $$ diff --git a/test/cram/9-error.t b/test/cram/9-error.t new file mode 100644 index 00000000..284f242b --- /dev/null +++ b/test/cram/9-error.t @@ -0,0 +1,46 @@ + $ error &> /dev/null & + $ $CURL localhost:8080/bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + +

404 Not Found

+
404 Not Found
+  
+  From: Application
+  Blame: Client
+  Severity: Warning
+  
+  Client: ::1:
+  
+  GET /bad
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+ + + $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + +

404 Not Found

+
404 Not Found
+  
+  From: Application
+  Blame: Client
+  Severity: Warning
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+ + + $ pkill -P $$ diff --git a/test/cram/a-log.t b/test/cram/a-log.t new file mode 100644 index 00000000..d7f431de --- /dev/null +++ b/test/cram/a-log.t @@ -0,0 +1,5 @@ + $ log &> /dev/null & + $ $CURL localhost:8080 + Good morning, world! + $ $CURL localhost:8080/fail + $ pkill -P $$ diff --git a/test/cram/b-session.t b/test/cram/b-session.t new file mode 100644 index 00000000..030fecfe --- /dev/null +++ b/test/cram/b-session.t @@ -0,0 +1,6 @@ + $ session &> /dev/null & + $ $CURL localhost:8080 -c cookie + You weren't logged in; but now you are! + $ $CURL localhost:8080 -b cookie + Welcome back, alice! + $ pkill -P $$ diff --git a/test/cram/c-cookie.t b/test/cram/c-cookie.t new file mode 100644 index 00000000..a7be6aa5 --- /dev/null +++ b/test/cram/c-cookie.t @@ -0,0 +1,7 @@ + $ cookie &> /dev/null & +The cookie is encrypted so we have cannot set it ourselves + $ $CURL localhost:8080 -c cookie + Set language preference; come again! + $ $CURL localhost:8080 -b cookie + Your preferred language is ut-OP! + $ pkill -P $$ diff --git a/test/cram/d-form.t b/test/cram/d-form.t new file mode 100644 index 00000000..62355ca3 --- /dev/null +++ b/test/cram/d-form.t @@ -0,0 +1,31 @@ + $ form &> /dev/null & + $ $CURL localhost:8080 -c cookies -b cookies | sed 's/value=.*/value=/' + + + + +
+ + + +
+ + + + + $ $CURL localhost:8080 -X POST + $ $CURL localhost:8080 -c cookies -b cookies | sed 's/value=.*/value=/' + + + + +
+ + + +
+ + + + + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index c93f6fde..787d539d 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -5,7 +5,23 @@ %{bin:router} %{bin:counter} %{bin:promise} - %{bin:echo-server})) + %{bin:echo-server} + %{bin:template} + %{bin:debug} + %{bin:error} + %{bin:log} + %{bin:session} + %{bin:cookie} + %{bin:form} + %{bin:json} + %{bin:static} + %{bin:upload} + %{bin:sql} + ; TODO reenable + ; %{bin:graphql} + %{bin:stream} + %{bin:websocket} + %{bin:https})) (env (_ @@ -19,4 +35,19 @@ ../../example/3-router/router.exe ../../example/4-counter/counter.exe ../../example/5-promise/promise.exe - (../../example/6-echo/echo.exe as echo-server)))) + (../../example/6-echo/echo.exe as echo-server) + ../../example/7-template/template.exe + ../../example/8-debug/debug.exe + ../../example/9-error/error.exe + ../../example/a-log/log.exe + ../../example/b-session/session.exe + ../../example/c-cookie/cookie.exe + ../../example/d-form/form.exe + ../../example/e-json/json.exe + ../../example/f-static/static.exe + ../../example/g-upload/upload.exe + ../../example/h-sql/sql.exe + ; ../../example/i-graphql/graphql.exe + ../../example/j-stream/stream.exe + ../../example/k-websocket/websocket.exe + ../../example/l-https/https.exe))) diff --git a/test/cram/f-static.t b/test/cram/f-static.t new file mode 100644 index 00000000..8504c8bd --- /dev/null +++ b/test/cram/f-static.t @@ -0,0 +1,9 @@ + $ mkdir testdata + $ echo "Hello" > hello + $ echo "World" > testdata/world + $ static &> /dev/null & + $ $CURL localhost:8080/static/hello + Hello + $ $CURL localhost:8080/static/testdata/world + World + $ pkill -P $$ From da5724553dedabec50bbda7974685fee899cd21c Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Sun, 18 May 2025 13:29:07 +0100 Subject: [PATCH 08/14] Promote test output --- test/cram/8-debug.t | 16 ++++++++++------ test/cram/9-error.t | 6 ++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t index 8a703323..6346b3ff 100644 --- a/test/cram/8-debug.t +++ b/test/cram/8-debug.t @@ -69,6 +69,7 @@ dream.client: ::1: dream.tls: false dream.request_id: + dream.fd: 6 dream.params: @@ -127,8 +128,8 @@

Debug Dump

Failure("The Web app failed!")
-  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
-  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
+  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
   
   From: Application
   Blame: Server
@@ -144,6 +145,7 @@
   dream.client: ::1:
   dream.tls: false
   dream.request_id: 
+  dream.fd: 6
   dream.params: 
@@ -201,8 +203,8 @@

Debug Dump

Failure("The Web app failed!")
-  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
-  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
+  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
   
   From: Application
   Blame: Server
@@ -218,6 +220,7 @@
   dream.client: ::1:
   dream.tls: false
   dream.request_id: 
+  dream.fd: 6
   dream.params: 
@@ -275,8 +278,8 @@

Debug Dump

Failure("The Web app failed!")
-  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
-  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
+  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
   
   From: Application
   Blame: Server
@@ -292,6 +295,7 @@
   dream.client: ::1:
   dream.tls: false
   dream.request_id: 
+  dream.fd: 6
   dream.params: 
diff --git a/test/cram/9-error.t b/test/cram/9-error.t index 284f242b..42eb57fa 100644 --- a/test/cram/9-error.t +++ b/test/cram/9-error.t @@ -18,7 +18,8 @@ dream.client: ::1: dream.tls: false - dream.request_id: + dream.request_id: + dream.fd: 6 $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' @@ -40,7 +41,8 @@ dream.client: ::1: dream.tls: false - dream.request_id: + dream.request_id: + dream.fd: 6 $ pkill -P $$ From b24a18f65d2d4e855d7bd264f868d7c07e9f4872 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 20 Mar 2026 15:12:35 +0100 Subject: [PATCH 09/14] Remove pkill --- test/cram/1-hello.t | 1 - test/cram/2-middleware.t | 1 - test/cram/3-router.t | 1 - test/cram/4-counter.t | 1 - test/cram/5-promise.t | 1 - test/cram/6-echo.t | 1 - test/cram/7-template.t | 2 -- test/cram/8-debug.t | 1 - test/cram/9-error.t | 1 - test/cram/a-log.t | 1 - test/cram/b-session.t | 1 - test/cram/c-cookie.t | 1 - test/cram/d-form.t | 2 -- test/cram/f-static.t | 1 - 14 files changed, 16 deletions(-) diff --git a/test/cram/1-hello.t b/test/cram/1-hello.t index dd024635..e2ab1514 100644 --- a/test/cram/1-hello.t +++ b/test/cram/1-hello.t @@ -1,4 +1,3 @@ $ hello &> /dev/null & $ $CURL localhost:8080 Good morning, world! - $ pkill -P $$ diff --git a/test/cram/2-middleware.t b/test/cram/2-middleware.t index 5edbc4f5..36605b22 100644 --- a/test/cram/2-middleware.t +++ b/test/cram/2-middleware.t @@ -1,4 +1,3 @@ $ middleware &> /dev/null & $ $CURL localhost:8080 Good morning, world! - $ pkill -P $$ diff --git a/test/cram/3-router.t b/test/cram/3-router.t index 13823ca4..e7a1b61e 100644 --- a/test/cram/3-router.t +++ b/test/cram/3-router.t @@ -1,4 +1,3 @@ $ router &> /dev/null & $ $CURL localhost:8080/echo/hello-world hello-world - $ pkill -P $$ diff --git a/test/cram/4-counter.t b/test/cram/4-counter.t index 26ceb5b5..efd95ae1 100644 --- a/test/cram/4-counter.t +++ b/test/cram/4-counter.t @@ -3,4 +3,3 @@ Responding to the 1. request! $ $CURL localhost:8080 Responding to the 2. request! - $ pkill -P $$ diff --git a/test/cram/5-promise.t b/test/cram/5-promise.t index e4d5ee3f..9ee0e06b 100644 --- a/test/cram/5-promise.t +++ b/test/cram/5-promise.t @@ -4,4 +4,3 @@ $ curl --no-progress-meter localhost:8080/fail $ $CURL localhost:8080 1 request(s) successful
1 request(s) failed - $ pkill -P $$ diff --git a/test/cram/6-echo.t b/test/cram/6-echo.t index e5f8cf41..ee7f2ee7 100644 --- a/test/cram/6-echo.t +++ b/test/cram/6-echo.t @@ -1,4 +1,3 @@ $ echo-server &> /dev/null & $ $CURL localhost:8080/echo --data "Hello, world!" Hello, world! - $ pkill -P $$ diff --git a/test/cram/7-template.t b/test/cram/7-template.t index ccab89a8..627c3353 100644 --- a/test/cram/7-template.t +++ b/test/cram/7-template.t @@ -5,5 +5,3 @@

The URL parameter was hello-world!

- - $ pkill -P $$ diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t index 6346b3ff..5fa4990d 100644 --- a/test/cram/8-debug.t +++ b/test/cram/8-debug.t @@ -299,4 +299,3 @@ dream.params: - $ pkill -P $$ diff --git a/test/cram/9-error.t b/test/cram/9-error.t index 42eb57fa..6485b2b5 100644 --- a/test/cram/9-error.t +++ b/test/cram/9-error.t @@ -45,4 +45,3 @@ dream.fd: 6 - $ pkill -P $$ diff --git a/test/cram/a-log.t b/test/cram/a-log.t index d7f431de..5afaba49 100644 --- a/test/cram/a-log.t +++ b/test/cram/a-log.t @@ -2,4 +2,3 @@ $ $CURL localhost:8080 Good morning, world! $ $CURL localhost:8080/fail - $ pkill -P $$ diff --git a/test/cram/b-session.t b/test/cram/b-session.t index 030fecfe..55898984 100644 --- a/test/cram/b-session.t +++ b/test/cram/b-session.t @@ -3,4 +3,3 @@ You weren't logged in; but now you are! $ $CURL localhost:8080 -b cookie Welcome back, alice! - $ pkill -P $$ diff --git a/test/cram/c-cookie.t b/test/cram/c-cookie.t index a7be6aa5..c258d735 100644 --- a/test/cram/c-cookie.t +++ b/test/cram/c-cookie.t @@ -4,4 +4,3 @@ The cookie is encrypted so we have cannot set it ourselves Set language preference; come again! $ $CURL localhost:8080 -b cookie Your preferred language is ut-OP! - $ pkill -P $$ diff --git a/test/cram/d-form.t b/test/cram/d-form.t index 62355ca3..fa564836 100644 --- a/test/cram/d-form.t +++ b/test/cram/d-form.t @@ -27,5 +27,3 @@ - - $ pkill -P $$ diff --git a/test/cram/f-static.t b/test/cram/f-static.t index 8504c8bd..0ebfa26a 100644 --- a/test/cram/f-static.t +++ b/test/cram/f-static.t @@ -6,4 +6,3 @@ Hello $ $CURL localhost:8080/static/testdata/world World - $ pkill -P $$ From 5324d3781f830e0491a74fb8cc7a8b7d01305937 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 20 Mar 2026 16:10:05 +0100 Subject: [PATCH 10/14] Add common.sh to simplify output --- dune-project | 2 +- test/cram/1-hello.t | 2 +- test/cram/2-middleware.t | 2 +- test/cram/3-router.t | 2 +- test/cram/4-counter.t | 4 ++-- test/cram/5-promise.t | 4 ++-- test/cram/6-echo.t | 2 +- test/cram/7-template.t | 2 +- test/cram/8-debug.t | 4 ++-- test/cram/9-error.t | 4 ++-- test/cram/a-log.t | 4 ++-- test/cram/b-session.t | 4 ++-- test/cram/c-cookie.t | 4 ++-- test/cram/common.sh | 3 +++ test/cram/d-form.t | 6 +++--- test/cram/dune | 7 ++----- test/cram/f-static.t | 4 ++-- 17 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 test/cram/common.sh diff --git a/dune-project b/dune-project index 37f995d6..e1b8e598 100644 --- a/dune-project +++ b/dune-project @@ -1 +1 @@ -(lang dune 3.0) +(lang dune 3.21) diff --git a/test/cram/1-hello.t b/test/cram/1-hello.t index e2ab1514..6c5e22c6 100644 --- a/test/cram/1-hello.t +++ b/test/cram/1-hello.t @@ -1,3 +1,3 @@ $ hello &> /dev/null & - $ $CURL localhost:8080 + $ curl_cmd / Good morning, world! diff --git a/test/cram/2-middleware.t b/test/cram/2-middleware.t index 36605b22..1f2cb1b5 100644 --- a/test/cram/2-middleware.t +++ b/test/cram/2-middleware.t @@ -1,3 +1,3 @@ $ middleware &> /dev/null & - $ $CURL localhost:8080 + $ curl_cmd / Good morning, world! diff --git a/test/cram/3-router.t b/test/cram/3-router.t index e7a1b61e..c5007cc5 100644 --- a/test/cram/3-router.t +++ b/test/cram/3-router.t @@ -1,3 +1,3 @@ $ router &> /dev/null & - $ $CURL localhost:8080/echo/hello-world + $ curl_cmd /echo/hello-world hello-world diff --git a/test/cram/4-counter.t b/test/cram/4-counter.t index efd95ae1..533f22f2 100644 --- a/test/cram/4-counter.t +++ b/test/cram/4-counter.t @@ -1,5 +1,5 @@ $ counter &> /dev/null & - $ $CURL localhost:8080 + $ curl_cmd / Responding to the 1. request! - $ $CURL localhost:8080 + $ curl_cmd / Responding to the 2. request! diff --git a/test/cram/5-promise.t b/test/cram/5-promise.t index 9ee0e06b..913dc758 100644 --- a/test/cram/5-promise.t +++ b/test/cram/5-promise.t @@ -1,6 +1,6 @@ $ promise &> /dev/null & - $ $CURL localhost:8080 + $ curl_cmd / 0 request(s) successful
0 request(s) failed $ curl --no-progress-meter localhost:8080/fail - $ $CURL localhost:8080 + $ curl_cmd / 1 request(s) successful
1 request(s) failed diff --git a/test/cram/6-echo.t b/test/cram/6-echo.t index ee7f2ee7..a27722bf 100644 --- a/test/cram/6-echo.t +++ b/test/cram/6-echo.t @@ -1,3 +1,3 @@ $ echo-server &> /dev/null & - $ $CURL localhost:8080/echo --data "Hello, world!" + $ curl_cmd /echo --data "Hello, world!" Hello, world! diff --git a/test/cram/7-template.t b/test/cram/7-template.t index 627c3353..796d0e9b 100644 --- a/test/cram/7-template.t +++ b/test/cram/7-template.t @@ -1,5 +1,5 @@ $ template &> /dev/null & - $ $CURL localhost:8080/hello-world + $ curl_cmd /hello-world

The URL parameter was hello-world!

diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t index 5fa4990d..4b904fed 100644 --- a/test/cram/8-debug.t +++ b/test/cram/8-debug.t @@ -1,5 +1,5 @@ $ debug &> /dev/null & - $ $CURL localhost:8080/bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' @@ -73,7 +73,7 @@ dream.params: - $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' diff --git a/test/cram/9-error.t b/test/cram/9-error.t index 6485b2b5..725379f7 100644 --- a/test/cram/9-error.t +++ b/test/cram/9-error.t @@ -1,5 +1,5 @@ $ error &> /dev/null & - $ $CURL localhost:8080/bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /'

404 Not Found

@@ -22,7 +22,7 @@ dream.fd: 6 - $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /'

404 Not Found

diff --git a/test/cram/a-log.t b/test/cram/a-log.t index 5afaba49..4fff44f0 100644 --- a/test/cram/a-log.t +++ b/test/cram/a-log.t @@ -1,4 +1,4 @@ $ log &> /dev/null & - $ $CURL localhost:8080 + $ curl_cmd / Good morning, world! - $ $CURL localhost:8080/fail + $ curl_cmd /fail diff --git a/test/cram/b-session.t b/test/cram/b-session.t index 55898984..970bb13c 100644 --- a/test/cram/b-session.t +++ b/test/cram/b-session.t @@ -1,5 +1,5 @@ $ session &> /dev/null & - $ $CURL localhost:8080 -c cookie + $ curl_cmd / -c cookie You weren't logged in; but now you are! - $ $CURL localhost:8080 -b cookie + $ curl_cmd / -b cookie Welcome back, alice! diff --git a/test/cram/c-cookie.t b/test/cram/c-cookie.t index c258d735..15f43dfd 100644 --- a/test/cram/c-cookie.t +++ b/test/cram/c-cookie.t @@ -1,6 +1,6 @@ $ cookie &> /dev/null & The cookie is encrypted so we have cannot set it ourselves - $ $CURL localhost:8080 -c cookie + $ curl_cmd / -c cookie Set language preference; come again! - $ $CURL localhost:8080 -b cookie + $ curl_cmd / -b cookie Your preferred language is ut-OP! diff --git a/test/cram/common.sh b/test/cram/common.sh new file mode 100644 index 00000000..6540c51a --- /dev/null +++ b/test/cram/common.sh @@ -0,0 +1,3 @@ +curl_cmd() { + curl --silent --retry 2 --retry-connrefused "localhost:8080$1" "${@:2}" +} diff --git a/test/cram/d-form.t b/test/cram/d-form.t index fa564836..c9486e28 100644 --- a/test/cram/d-form.t +++ b/test/cram/d-form.t @@ -1,5 +1,5 @@ $ form &> /dev/null & - $ $CURL localhost:8080 -c cookies -b cookies | sed 's/value=.*/value=/' + $ curl_cmd / -c cookies -b cookies | sed 's/value=.*/value=/' @@ -13,8 +13,8 @@ - $ $CURL localhost:8080 -X POST - $ $CURL localhost:8080 -c cookies -b cookies | sed 's/value=.*/value=/' + $ curl_cmd / -X POST + $ curl_cmd / -c cookies -b cookies | sed 's/value=.*/value=/' diff --git a/test/cram/dune b/test/cram/dune index 787d539d..771a0c8e 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -21,14 +21,11 @@ ; %{bin:graphql} %{bin:stream} %{bin:websocket} - %{bin:https})) + %{bin:https}) + (setup_scripts common.sh)) (env (_ - (env-vars - ; --silent: Remove progress bar and error messages from retries - ; --retry 5 --retry-connrefused: retry in case curl is run before the server is available - (CURL "curl --silent --retry 2 --retry-connrefused")) (binaries ../../example/1-hello/hello.exe ../../example/2-middleware/middleware.exe diff --git a/test/cram/f-static.t b/test/cram/f-static.t index 0ebfa26a..fbcaaa6b 100644 --- a/test/cram/f-static.t +++ b/test/cram/f-static.t @@ -2,7 +2,7 @@ $ echo "Hello" > hello $ echo "World" > testdata/world $ static &> /dev/null & - $ $CURL localhost:8080/static/hello + $ curl_cmd /static/hello Hello - $ $CURL localhost:8080/static/testdata/world + $ curl_cmd /static/testdata/world World From efb7377052df240ee95b1853cf1ab167a82eb246 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 20 Mar 2026 17:44:12 +0100 Subject: [PATCH 11/14] Clean up test output --- test/cram/7-template.t | 1 + test/cram/8-debug.t | 10 +++------- test/cram/9-error.t | 2 -- test/cram/a-log.t | 1 + test/cram/common.sh | 4 +++- test/cram/d-form.t | 2 ++ 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/cram/7-template.t b/test/cram/7-template.t index 796d0e9b..85d4a9e5 100644 --- a/test/cram/7-template.t +++ b/test/cram/7-template.t @@ -5,3 +5,4 @@

The URL parameter was hello-world!

+ diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t index 4b904fed..ebcbf298 100644 --- a/test/cram/8-debug.t +++ b/test/cram/8-debug.t @@ -63,7 +63,6 @@ GET /bad Host: localhost:8080 - User-Agent: curl/8.9.1 Accept: */* dream.client: ::1: @@ -129,7 +128,7 @@

Debug Dump

Failure("The Web app failed!")
   Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
-  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
+  Called from Logs.Tag.find in file "src/logs.ml", line 144, characters 14-32
   
   From: Application
   Blame: Server
@@ -139,7 +138,6 @@
   
   GET /fail
   Host: localhost:8080
-  User-Agent: curl/8.9.1
   Accept: */*
   
   dream.client: ::1:
@@ -204,7 +202,7 @@
       

Debug Dump

Failure("The Web app failed!")
   Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
-  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
+  Called from Logs.Tag.find in file "src/logs.ml", line 144, characters 14-32
   
   From: Application
   Blame: Server
@@ -214,7 +212,6 @@
   
   GET /fail
   Host: localhost:8080
-  User-Agent: curl/8.9.1
   Accept: */*
   
   dream.client: ::1:
@@ -279,7 +276,7 @@
       

Debug Dump

Failure("The Web app failed!")
   Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
-  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
+  Called from Logs.Tag.find in file "src/logs.ml", line 144, characters 14-32
   
   From: Application
   Blame: Server
@@ -289,7 +286,6 @@
   
   GET /fail
   Host: localhost:8080
-  User-Agent: curl/8.9.1
   Accept: */*
   
   dream.client: ::1:
diff --git a/test/cram/9-error.t b/test/cram/9-error.t
index 725379f7..0091c5a8 100644
--- a/test/cram/9-error.t
+++ b/test/cram/9-error.t
@@ -13,7 +13,6 @@
   
   GET /bad
   Host: localhost:8080
-  User-Agent: curl/8.9.1
   Accept: */*
   
   dream.client: ::1:
@@ -36,7 +35,6 @@
   
   GET /fail
   Host: localhost:8080
-  User-Agent: curl/8.9.1
   Accept: */*
   
   dream.client: ::1:
diff --git a/test/cram/a-log.t b/test/cram/a-log.t
index 4fff44f0..7f0ebb6e 100644
--- a/test/cram/a-log.t
+++ b/test/cram/a-log.t
@@ -2,3 +2,4 @@
   $ curl_cmd /
   Good morning, world!
   $ curl_cmd /fail
+  [1]
diff --git a/test/cram/common.sh b/test/cram/common.sh
index 6540c51a..7d17f0ac 100644
--- a/test/cram/common.sh
+++ b/test/cram/common.sh
@@ -1,3 +1,5 @@
 curl_cmd() {
-  curl --silent --retry 2 --retry-connrefused "localhost:8080$1" "${@:2}"
+  # Filter out User-Agent header to avoid test flakiness from curl's default UA
+    curl --silent --retry 2 --retry-connrefused "localhost:8080$1" "${@:2}" 2>&1 \
+        | grep -v "User-Agent:"
 }
diff --git a/test/cram/d-form.t b/test/cram/d-form.t
index c9486e28..237ca68c 100644
--- a/test/cram/d-form.t
+++ b/test/cram/d-form.t
@@ -14,6 +14,7 @@
   
   
   $ curl_cmd / -X POST
+  [1]
   $ curl_cmd / -c cookies -b cookies | sed 's/value=.*/value=/'
   
   
@@ -27,3 +28,4 @@
   
   
   
+  

From ae99e0e7cbbb6d4e6b04e3ad335b5e32cfe169b5 Mon Sep 17 00:00:00 2001
From: Sebastian Willenbrink 
Date: Wed, 25 Mar 2026 19:15:23 +0100
Subject: [PATCH 12/14] Allow setting the port via DREAM_PORT envvar

---
 src/dream.mli    |  4 +++-
 src/http/http.ml | 12 ++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/dream.mli b/src/dream.mli
index d5b98d97..0b8eb8d0 100644
--- a/src/dream.mli
+++ b/src/dream.mli
@@ -2124,7 +2124,9 @@ val run :
 
     - [~interface] is the network interface to listen on. Defaults to
       ["localhost"]. Use ["0.0.0.0"] to listen on all interfaces.
-    - [~port] is the port to listen on. Defaults to [8080].
+    - [~port] is the port to listen on. Defaults to [8080], or the value of the
+      environment variable [DREAM_PORT], if set. [~port] takes precedence over
+      [DREAM_PORT].
     - If [~socket_path] is specified, Dream will listen on a Unix domain socket
       at the given path, and ignore [~interface] and [~port].
     - [~stop] is a promise that causes the server to stop accepting new
diff --git a/src/http/http.ml b/src/http/http.ml
index 6cce597a..e60e8013 100644
--- a/src/http/http.ml
+++ b/src/http/http.ml
@@ -687,6 +687,12 @@ let on_termination_signal () =
   ignore (Lwt_unix.on_signal Sys.sigint (fun _ -> Lwt.wakeup_later int_resolve ()));
   Lwt.pick [term_promise; int_promise]
 
+let get_port ?port () =
+  match port with
+  | Some p -> p
+  | None ->
+    (try int_of_string (Sys.getenv "DREAM_PORT") with Not_found -> default_port)
+
 let network ~port ~socket_path =
   match socket_path with
   | None -> `Inet port
@@ -694,7 +700,7 @@ let network ~port ~socket_path =
 
 let serve
     ?(interface = default_interface)
-    ?(port = default_port)
+    ?port
     ?socket_path
     ?stop
     ?(error_handler = Error_handler.default)
@@ -704,6 +710,7 @@ let serve
     ?(builtins = true)
     user's_dream_handler =
 
+  let port = get_port ?port () in
   serve_with_maybe_https
     "serve"
     ~interface
@@ -722,7 +729,7 @@ let serve
 
 let run
     ?(interface = default_interface)
-    ?(port = default_port)
+    ?port
     ?socket_path
     ?stop
     ?(error_handler = Error_handler.default)
@@ -734,6 +741,7 @@ let run
     ?adjust_terminal
     user's_dream_handler =
 
+  let port = get_port ?port () in
   let () = if Sys.unix then
     Sys.(set_signal sigpipe Signal_ignore)
   in

From 26043b9d04fc8d58f83cb14700264890204cc8af Mon Sep 17 00:00:00 2001
From: Sebastian Willenbrink 
Date: Wed, 25 Mar 2026 19:24:54 +0100
Subject: [PATCH 13/14] Run tests in parallel, unify curl output filtering

---
 test/cram/5-promise.t |  2 +-
 test/cram/8-debug.t   | 16 ++++++++++------
 test/cram/9-error.t   | 10 ++++++----
 test/cram/README.md   |  1 -
 test/cram/a-log.t     |  1 -
 test/cram/common.sh   | 13 ++++++++++---
 test/cram/d-form.t    |  1 -
 7 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/test/cram/5-promise.t b/test/cram/5-promise.t
index 913dc758..8bfb89c2 100644
--- a/test/cram/5-promise.t
+++ b/test/cram/5-promise.t
@@ -1,6 +1,6 @@
   $ promise &> /dev/null &
   $ curl_cmd /
     0 request(s) successful
0 request(s) failed - $ curl --no-progress-meter localhost:8080/fail + $ curl --no-progress-meter localhost:$DREAM_PORT/fail $ curl_cmd / 1 request(s) successful
1 request(s) failed diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t index ebcbf298..59047ebf 100644 --- a/test/cram/8-debug.t +++ b/test/cram/8-debug.t @@ -1,5 +1,5 @@ $ debug &> /dev/null & - $ curl_cmd /bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /bad @@ -62,7 +62,8 @@ Client: ::1: GET /bad - Host: localhost:8080 + Host: localhost: + User-Agent: Accept: */* dream.client: ::1: @@ -72,7 +73,7 @@ dream.params:
- $ curl_cmd /fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /fail @@ -137,7 +138,8 @@ Client: ::1: GET /fail - Host: localhost:8080 + Host: localhost: + User-Agent: Accept: */* dream.client: ::1: @@ -211,7 +213,8 @@ Client: ::1: GET /fail - Host: localhost:8080 + Host: localhost: + User-Agent: Accept: */* dream.client: ::1: @@ -285,7 +288,8 @@ Client: ::1: GET /fail - Host: localhost:8080 + Host: localhost: + User-Agent: Accept: */* dream.client: ::1: diff --git a/test/cram/9-error.t b/test/cram/9-error.t index 0091c5a8..9884a6e9 100644 --- a/test/cram/9-error.t +++ b/test/cram/9-error.t @@ -1,5 +1,5 @@ $ error &> /dev/null & - $ curl_cmd /bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /bad

404 Not Found

@@ -12,7 +12,8 @@ Client: ::1: GET /bad - Host: localhost:8080 + Host: localhost: + User-Agent: Accept: */* dream.client: ::1: @@ -21,7 +22,7 @@ dream.fd: 6
- $ curl_cmd /fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + $ curl_cmd /fail

404 Not Found

@@ -34,7 +35,8 @@ Client: ::1: GET /fail - Host: localhost:8080 + Host: localhost: + User-Agent: Accept: */* dream.client: ::1: diff --git a/test/cram/README.md b/test/cram/README.md index 8eb67c92..cdeeb1bb 100644 --- a/test/cram/README.md +++ b/test/cram/README.md @@ -3,4 +3,3 @@ * Use `$CURL` instead of `curl` as we need retries in case the server is not yet available. * Pipe the output of the server to `/dev/null` as it includes timestamps. * Run `pkill -P $$` to kill the server at the end of the test. -* Execute only one test at a time (e.g. `dune runtest -j1`) as the tests all use the same port diff --git a/test/cram/a-log.t b/test/cram/a-log.t index 7f0ebb6e..4fff44f0 100644 --- a/test/cram/a-log.t +++ b/test/cram/a-log.t @@ -2,4 +2,3 @@ $ curl_cmd / Good morning, world! $ curl_cmd /fail - [1] diff --git a/test/cram/common.sh b/test/cram/common.sh index 7d17f0ac..48386889 100644 --- a/test/cram/common.sh +++ b/test/cram/common.sh @@ -1,5 +1,12 @@ +set -o pipefail +set -o nounset + +export DREAM_PORT=$((10000 + RANDOM % 55000)) + curl_cmd() { - # Filter out User-Agent header to avoid test flakiness from curl's default UA - curl --silent --retry 2 --retry-connrefused "localhost:8080$1" "${@:2}" 2>&1 \ - | grep -v "User-Agent:" + curl --silent --retry 2 --retry-connrefused "localhost:$DREAM_PORT$1" "${@:2}" 2>&1 \ + | sed 's/User-Agent: .*/User-Agent: /' \ + | sed 's/::1:[0-9]*/::1:/' \ + | sed 's/dream.request_id: [0-9]*/dream.request_id: /' \ + | sed 's/localhost:[0-9]*/localhost:/' } diff --git a/test/cram/d-form.t b/test/cram/d-form.t index 237ca68c..c2e47681 100644 --- a/test/cram/d-form.t +++ b/test/cram/d-form.t @@ -14,7 +14,6 @@ $ curl_cmd / -X POST - [1] $ curl_cmd / -c cookies -b cookies | sed 's/value=.*/value=/' From 1c0bc24b20f98be69519c054a5329f7c96821f70 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Wed, 25 Mar 2026 19:59:15 +0100 Subject: [PATCH 14/14] Add examples 3, i, j, l --- test/cram/README.md | 1 - test/cram/dune | 8 ++++---- test/cram/e-json.t | 3 +++ test/cram/i-graphql.t | 3 +++ test/cram/j-stream.t | 3 +++ test/cram/l-https.t | 6 ++++++ 6 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 test/cram/e-json.t create mode 100644 test/cram/i-graphql.t create mode 100644 test/cram/j-stream.t create mode 100644 test/cram/l-https.t diff --git a/test/cram/README.md b/test/cram/README.md index cdeeb1bb..278349b9 100644 --- a/test/cram/README.md +++ b/test/cram/README.md @@ -2,4 +2,3 @@ * Make the example available via the dune file, e.g. `env _ (binaries ../../example/1-hello/hello.exe)))` * Use `$CURL` instead of `curl` as we need retries in case the server is not yet available. * Pipe the output of the server to `/dev/null` as it includes timestamps. -* Run `pkill -P $$` to kill the server at the end of the test. diff --git a/test/cram/dune b/test/cram/dune index 771a0c8e..4fb34e92 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -17,11 +17,11 @@ %{bin:static} %{bin:upload} %{bin:sql} - ; TODO reenable - ; %{bin:graphql} + %{bin:graphql} %{bin:stream} %{bin:websocket} - %{bin:https}) + %{bin:https} + ../../example/h-sql/db.sqlite) (setup_scripts common.sh)) (env @@ -44,7 +44,7 @@ ../../example/f-static/static.exe ../../example/g-upload/upload.exe ../../example/h-sql/sql.exe - ; ../../example/i-graphql/graphql.exe + ../../example/i-graphql/graphql.exe ../../example/j-stream/stream.exe ../../example/k-websocket/websocket.exe ../../example/l-https/https.exe))) diff --git a/test/cram/e-json.t b/test/cram/e-json.t new file mode 100644 index 00000000..bc263a9a --- /dev/null +++ b/test/cram/e-json.t @@ -0,0 +1,3 @@ + $ json &> /dev/null & + $ curl_cmd / -X POST -H "Content-Type: application/json" -H "Origin: http://localhost:$DREAM_PORT" -d '{"message": "Hello"}' + "Hello" diff --git a/test/cram/i-graphql.t b/test/cram/i-graphql.t new file mode 100644 index 00000000..1a08d513 --- /dev/null +++ b/test/cram/i-graphql.t @@ -0,0 +1,3 @@ + $ graphql &> /dev/null & + $ curl_cmd /graphql -X POST -H "Content-Type: application/json" -H "Origin: http://localhost:$DREAM_PORT" -d '{"query": "{ users { id name } }"}' + {"data":{"users":[{"id":1,"name":"alice"},{"id":2,"name":"bob"}]}} diff --git a/test/cram/j-stream.t b/test/cram/j-stream.t new file mode 100644 index 00000000..4d19907b --- /dev/null +++ b/test/cram/j-stream.t @@ -0,0 +1,3 @@ + $ stream &> /dev/null & + $ curl_cmd /echo --data "Hello, world!" + Hello, world! diff --git a/test/cram/l-https.t b/test/cram/l-https.t new file mode 100644 index 00000000..c3b450b0 --- /dev/null +++ b/test/cram/l-https.t @@ -0,0 +1,6 @@ + $ https &> /dev/null & + $ curl --silent --retry 2 --retry-connrefused "https://localhost:$DREAM_PORT/" -k + Good morning, world! + $ curl --silent --retry 2 --retry-connrefused "https://localhost:$DREAM_PORT/" -w '%{http_code}' -o /dev/null + 000 + [60]