File tree Expand file tree Collapse file tree 10 files changed +196
-0
lines changed Expand file tree Collapse file tree 10 files changed +196
-0
lines changed Original file line number Diff line number Diff line change 1+ # Dream
2+
3+ ## Overview
4+
5+ Most of all of the code is inside of ` test_dream/bin/main.ml ` file.
6+
7+ ## Implemented tests
8+
9+ | Test Name | Endpoint |
10+ | ------------| -------------------------------|
11+ | Plain text | http://0.0.0.0:8080/plaintext |
12+ | Json | http://0.0.0.0:8080/json |
13+
14+ ## Headers
15+
16+ A simple middleware was added that adds the required headers for the Techempower Benchmarks.
17+ The date header is refreshed only once per second as allowed by the rules for performance.
18+
19+ ## Dependencies
20+
21+ The ` test_dream/dune-project ` and ` test_dream/bin/dune ` are where dependencies are managed
22+ for this project. If you add a dependency to those locations and then run the following:
23+
24+ ```
25+ cd test_dream
26+ dune build test_dream.opam
27+ opam install --yes --deps-only .
28+ ```
29+
30+ You will update the opam package list and install your changes locally.
31+
32+ ## Running tests
33+
34+ $ tfb --mode verify --test dream
35+
Original file line number Diff line number Diff line change 1+ {
2+ "framework" : " dream" ,
3+ "tests" : [
4+ {
5+ "default" : {
6+ "json_url" : " /json" ,
7+ "plaintext_url" : " /plaintext" ,
8+ "port" : 8080 ,
9+ "approach" : " Realistic" ,
10+ "classification" : " Fullstack" ,
11+ "database" : " postgres" ,
12+ "framework" : " Dream" ,
13+ "language" : " OCaml" ,
14+ "flavor" : " None" ,
15+ "orm" : " Micro" ,
16+ "platform" : " http/af" ,
17+ "webserver" : " None" ,
18+ "os" : " Linux" ,
19+ "database_os" : " Linux" ,
20+ "display_name" : " Dream" ,
21+ "notes" : " " ,
22+ "versus" : " httpaf"
23+ }
24+ }
25+ ]
26+ }
Original file line number Diff line number Diff line change 1+ FROM ocaml/opam:debian-ocaml-5.1
2+ COPY ./dream_test/ /app
3+ WORKDIR /app
4+ USER root
5+ RUN apt install -y libgmp-dev libev-dev pkg-config libssl-dev
6+ RUN opam install --yes --deps-only .
7+ RUN opam install dune
8+ RUN eval $(opam env)
9+ RUN opam exec -- dune build --profile release
10+ CMD [ "./_build/default/bin/main.exe" ]
11+ EXPOSE 8080
12+
Original file line number Diff line number Diff line change 1+ (executable
2+ (public_name dream_test)
3+ (name main)
4+ (preprocess (pps lwt_ppx ppx_yojson_conv))
5+ (libraries dream_test dream ppx_yojson_conv calendar))
Original file line number Diff line number Diff line change 1+ open Ppx_yojson_conv_lib.Yojson_conv.Primitives
2+
3+ type message_object = {
4+ message : string ;
5+ } [@@ deriving yojson ]
6+
7+ let time_cache = Atomic. make false ;;
8+ let time_ref = ref (" None" );;
9+
10+ let time () =
11+ if not @@ Atomic. get time_cache
12+ then begin
13+ time_ref := CalendarLib.Printer.Calendar. sprint " %a, %d %b %Y %H:%M:%S UTC" @@ CalendarLib.Calendar. now () ;
14+ Atomic. set time_cache true ;
15+ (! time_ref)
16+ end
17+ else
18+ (! time_ref);;
19+
20+ let tech_empower_headers (inner_handler : Dream.handler ) =
21+ (fun (req ) ->
22+ let % lwt res = inner_handler req in
23+ Dream. set_header res " Server" " dream" ;
24+ Dream. set_header res " Date" @@ time () ;
25+ Lwt. return res
26+ );;
27+
28+ let rec timer () =
29+ Unix. sleepf 0.9 ;
30+ Atomic. set time_cache false ;
31+ timer() ;;
32+
33+ let () =
34+ let time_invalidator = Domain. spawn(fun () -> timer () ) in
35+ Dream. run ~interface: " 0.0.0.0"
36+ @@ tech_empower_headers
37+ @@ Dream. router [
38+ Dream. get " /" (fun _ ->
39+ Dream. html " Hello, world!"
40+ );
41+ Dream. get " /plaintext" (fun _ ->
42+ Dream. response ~headers: [(" Content-Type" , " text/plain" )]
43+ " Hello, world!"
44+ |> Lwt. return
45+ );
46+ Dream. get " /json" (fun _ ->
47+ { message = " Hello, world!" }
48+ |> yojson_of_message_object
49+ |> Yojson.Safe. to_string
50+ |> Dream. json
51+ );
52+ ];
53+ Domain. join time_invalidator;;
Original file line number Diff line number Diff line change 1+ # This file is generated by dune, edit dune-project instead
2+ opam-version: "2.0"
3+ synopsis: "A short synopsis"
4+ description: "A longer description"
5+ maintainer: ["Maintainer Name"]
6+ authors: ["Author Name"]
7+ license: "LICENSE"
8+ tags: ["topics" "to describe" "your" "project"]
9+ homepage: "https://github.com/username/reponame"
10+ doc: "https://url/to/documentation"
11+ bug-reports: "https://github.com/username/reponame/issues"
12+ depends: [
13+ "ocaml"
14+ "dune" {>= "3.14"}
15+ "dream"
16+ "lwt"
17+ "ppx_yojson_conv"
18+ "calendar"
19+ "odoc" {with-doc}
20+ ]
21+ build: [
22+ ["dune" "subst"] {dev}
23+ [
24+ "dune"
25+ "build"
26+ "-p"
27+ name
28+ "-j"
29+ jobs
30+ "@install"
31+ "@runtest" {with-test}
32+ "@doc" {with-doc}
33+ ]
34+ ]
35+ dev-repo: "git+https://github.com/username/reponame.git"
Original file line number Diff line number Diff line change 1+ (lang dune 3 .14)
2+
3+ (name dream_test)
4+
5+ ( generate_opam_files true )
6+
7+ ( source
8+ ( github username/reponame) )
9+
10+ ( authors " Author Name" )
11+
12+ ( maintainers " Maintainer Name" )
13+
14+ ( license LICENSE)
15+
16+ ( documentation https://url/to/documentation)
17+
18+ ( package
19+ (name dream_test)
20+ (synopsis " A short synopsis" )
21+ ( description " A longer description" )
22+ ( depends ocaml dune dream lwt ppx_yojson_conv calendar)
23+ ( tags
24+ ( topics " to describe" your project) ) )
25+
26+ ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
Original file line number Diff line number Diff line change 1+ (library
2+ (name dream_test))
Original file line number Diff line number Diff line change 1+ (test
2+ (name test_dream_test))
You can’t perform that action at this time.
0 commit comments