forked from aantron/dream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a few missing dependencies to dream.opam; allow the dune-project …
…to run cram tests; add a cram test for aantron#118; propose a small fix for aantron#118
- Loading branch information
Showing
7 changed files
with
103 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
(lang dune 2.7) | ||
(cram enable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(cram | ||
(applies_to :whole_subtree)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(executable | ||
(name econnreset) | ||
(libraries dream)) | ||
|
||
(cram | ||
(deps %{exe:econnreset.exe})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(* This file is part of Dream, released under the MIT license. See LICENSE.md | ||
for details, or visit https://github.com/aantron/dream. | ||
Copyright 2021 Anton Bachin *) | ||
|
||
let serve port = | ||
print_endline "server mode"; | ||
Dream.run ~greeting:false ~port (fun _ -> Unix.sleepf 10.0; Dream.html "Hello") | ||
|
||
let client port = | ||
print_endline "client mode"; | ||
let open Unix in | ||
let fd = socket PF_INET6 SOCK_STREAM 0 in | ||
(* force the client to send a TCP RST packet if it fails during connection *) | ||
setsockopt_optint fd SO_LINGER (Some 0); | ||
let _ = connect fd (ADDR_INET (inet6_addr_loopback ,port)) in | ||
ignore @@ failwith "sending RST"; | ||
shutdown fd SHUTDOWN_ALL | ||
|
||
let () = | ||
let server = ref(false) in | ||
let port = ref(-1) in | ||
let usage = "Test for ECONNRESET errors being reported" in | ||
Arg.parse [ | ||
"-p", Set_int port, "sets the port (required)"; | ||
"-s", Set server, "enables the server on port [port], if not set sends a TCP RST on [port]" | ||
] (fun _ -> ()) usage; | ||
|
||
let port = !port in | ||
if port > 65535 || port < 1025 then failwith "Port argument (-p) must set and be between 1025-65535"; | ||
|
||
if !server then serve port | ||
else client port | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Start a Dream server | ||
|
||
$ ./econnreset.exe -s -p 9191 &> test.log & | ||
$ export PID=$! | ||
$ sleep 1 | ||
|
||
Force a connection reset - will log a few errors | ||
|
||
$ ./econnreset.exe -p 9191 | ||
|
||
Does the log contain an error line for the ECONNRESET? An error code of [1] is "good", meaning no line was found. | ||
|
||
$ kill "${PID}" | ||
$ cat test.log | grep 'ERROR' | grep 'ECONNRESET' | ||
|
||
Does the log contain an info line with custom string for the ECONNRESET? | ||
|
||
$ cat test.log | grep 'INFO' | grep 'Connection Reset at Client' | wc -l |